]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: stmmac: always allocate mac_device_info
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tue, 11 Nov 2025 11:26:44 +0000 (11:26 +0000)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 13 Nov 2025 16:03:19 +0000 (17:03 +0100)
The ->setup() method implemented by dwmac-loongson and dwmac-sun8i
allocate the mac_device_info structure, as does stmmac_hwif_init().
This makes no sense.

Have stmmac_hwif_init() always allocate this structure, and pass it to
the ->setup() method to initialise when it is provided. Rename this
method to "mac_setup" to more accurately describe what it is doing.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/E1vImWK-0000000DrIx-28vO@rmk-PC.armlinux.org.uk
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
drivers/net/ethernet/stmicro/stmmac/hwif.c
include/linux/stmmac.h

index 2a3ac0136cdbcfa3c854ae86d5d27ffc58d10cf8..dd2fc39ec3e22597f3d9fb7966b662c1bcc8f058 100644 (file)
@@ -320,10 +320,9 @@ static int loongson_dwmac_dma_interrupt(struct stmmac_priv *priv,
        return ret;
 }
 
-static struct mac_device_info *loongson_dwmac_setup(void *apriv)
+static int loongson_dwmac_setup(void *apriv, struct mac_device_info *mac)
 {
        struct stmmac_priv *priv = apriv;
-       struct mac_device_info *mac;
        struct stmmac_dma_ops *dma;
        struct loongson_data *ld;
        struct pci_dev *pdev;
@@ -331,13 +330,9 @@ static struct mac_device_info *loongson_dwmac_setup(void *apriv)
        ld = priv->plat->bsp_priv;
        pdev = to_pci_dev(priv->device);
 
-       mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
-       if (!mac)
-               return NULL;
-
        dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL);
        if (!dma)
-               return NULL;
+               return -ENOMEM;
 
        /* The Loongson GMAC and GNET devices are based on the DW GMAC
         * v3.50a and v3.73a IP-cores. But the HW designers have changed
@@ -396,7 +391,7 @@ static struct mac_device_info *loongson_dwmac_setup(void *apriv)
        mac->mii.clk_csr_shift = 2;
        mac->mii.clk_csr_mask = GENMASK(5, 2);
 
-       return mac;
+       return 0;
 }
 
 static int loongson_dwmac_msi_config(struct pci_dev *pdev,
@@ -598,7 +593,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
                goto err_disable_device;
 
        plat->bsp_priv = ld;
-       plat->setup = loongson_dwmac_setup;
+       plat->mac_setup = loongson_dwmac_setup;
        plat->fix_soc_reset = loongson_dwmac_fix_reset;
        plat->suspend = loongson_dwmac_suspend;
        plat->resume = loongson_dwmac_resume;
index 5d871b2cd111c26d367ea7cc22728f07ec60f60c..7434d4bbb52609049598a5de5aec28c355645a5b 100644 (file)
@@ -1040,15 +1040,10 @@ static const struct stmmac_ops sun8i_dwmac_ops = {
        .set_mac_loopback = sun8i_dwmac_set_mac_loopback,
 };
 
-static struct mac_device_info *sun8i_dwmac_setup(void *ppriv)
+static int sun8i_dwmac_setup(void *ppriv, struct mac_device_info *mac)
 {
-       struct mac_device_info *mac;
        struct stmmac_priv *priv = ppriv;
 
-       mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
-       if (!mac)
-               return NULL;
-
        mac->pcsr = priv->ioaddr;
        mac->mac = &sun8i_dwmac_ops;
        mac->dma = &sun8i_dwmac_dma_ops;
@@ -1079,7 +1074,7 @@ static struct mac_device_info *sun8i_dwmac_setup(void *ppriv)
        /* Synopsys Id is not available */
        priv->synopsys_id = 0;
 
-       return mac;
+       return 0;
 }
 
 static struct regmap *sun8i_dwmac_get_syscon_from_dev(struct device_node *node)
@@ -1192,7 +1187,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
        plat_dat->bsp_priv = gmac;
        plat_dat->init = sun8i_dwmac_init;
        plat_dat->exit = sun8i_dwmac_exit;
-       plat_dat->setup = sun8i_dwmac_setup;
+       plat_dat->mac_setup = sun8i_dwmac_setup;
        plat_dat->tx_fifo_size = 4096;
        plat_dat->rx_fifo_size = 16384;
 
index ee612cadbd77f17571e7f9d00e9a7bd09bb2b420..014f7cd79a3ccc9ba6a4b683200cde23663681dc 100644 (file)
@@ -347,17 +347,19 @@ int stmmac_hwif_init(struct stmmac_priv *priv)
                        priv->estaddr = priv->ioaddr + EST_XGMAC_OFFSET;
        }
 
+       mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+       if (!mac)
+               return -ENOMEM;
+
        /* Check for HW specific setup first */
-       if (priv->plat->setup) {
-               mac = priv->plat->setup(priv);
+       if (priv->plat->mac_setup) {
+               ret = priv->plat->mac_setup(priv, mac);
+               if (ret)
+                       return ret;
+
                needs_setup = false;
-       } else {
-               mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
        }
 
-       if (!mac)
-               return -ENOMEM;
-
        spin_lock_init(&mac->irq_ctrl_lock);
 
        /* Fallback to generic HW */
index 48e9f1d4e17e86f919710251dc9d463b7bf50b34..4f70a6551e68c8a3014789f4e66d9e1db3210c44 100644 (file)
@@ -192,6 +192,8 @@ enum dwmac_core_type {
 #define STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP      BIT(12)
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY   BIT(13)
 
+struct mac_device_info;
+
 struct plat_stmmacenet_data {
        enum dwmac_core_type core_type;
        int bus_id;
@@ -266,7 +268,7 @@ struct plat_stmmacenet_data {
        void (*exit)(struct platform_device *pdev, void *priv);
        int (*suspend)(struct device *dev, void *priv);
        int (*resume)(struct device *dev, void *priv);
-       struct mac_device_info *(*setup)(void *priv);
+       int (*mac_setup)(void *priv, struct mac_device_info *mac);
        int (*clks_config)(void *priv, bool enabled);
        int (*crosststamp)(ktime_t *device, struct system_counterval_t *system,
                           void *ctx);