Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: stmmac: always allocate mac_device_info

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>

authored by

Russell King (Oracle) and committed by
Paolo Abeni
f694d215 d0af55df

+20 -26
+4 -9
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
··· 320 320 return ret; 321 321 } 322 322 323 - static struct mac_device_info *loongson_dwmac_setup(void *apriv) 323 + static int loongson_dwmac_setup(void *apriv, struct mac_device_info *mac) 324 324 { 325 325 struct stmmac_priv *priv = apriv; 326 - struct mac_device_info *mac; 327 326 struct stmmac_dma_ops *dma; 328 327 struct loongson_data *ld; 329 328 struct pci_dev *pdev; ··· 330 331 ld = priv->plat->bsp_priv; 331 332 pdev = to_pci_dev(priv->device); 332 333 333 - mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL); 334 - if (!mac) 335 - return NULL; 336 - 337 334 dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL); 338 335 if (!dma) 339 - return NULL; 336 + return -ENOMEM; 340 337 341 338 /* The Loongson GMAC and GNET devices are based on the DW GMAC 342 339 * v3.50a and v3.73a IP-cores. But the HW designers have changed ··· 391 396 mac->mii.clk_csr_shift = 2; 392 397 mac->mii.clk_csr_mask = GENMASK(5, 2); 393 398 394 - return mac; 399 + return 0; 395 400 } 396 401 397 402 static int loongson_dwmac_msi_config(struct pci_dev *pdev, ··· 593 598 goto err_disable_device; 594 599 595 600 plat->bsp_priv = ld; 596 - plat->setup = loongson_dwmac_setup; 601 + plat->mac_setup = loongson_dwmac_setup; 597 602 plat->fix_soc_reset = loongson_dwmac_fix_reset; 598 603 plat->suspend = loongson_dwmac_suspend; 599 604 plat->resume = loongson_dwmac_resume;
+3 -8
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
··· 1040 1040 .set_mac_loopback = sun8i_dwmac_set_mac_loopback, 1041 1041 }; 1042 1042 1043 - static struct mac_device_info *sun8i_dwmac_setup(void *ppriv) 1043 + static int sun8i_dwmac_setup(void *ppriv, struct mac_device_info *mac) 1044 1044 { 1045 - struct mac_device_info *mac; 1046 1045 struct stmmac_priv *priv = ppriv; 1047 - 1048 - mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL); 1049 - if (!mac) 1050 - return NULL; 1051 1046 1052 1047 mac->pcsr = priv->ioaddr; 1053 1048 mac->mac = &sun8i_dwmac_ops; ··· 1074 1079 /* Synopsys Id is not available */ 1075 1080 priv->synopsys_id = 0; 1076 1081 1077 - return mac; 1082 + return 0; 1078 1083 } 1079 1084 1080 1085 static struct regmap *sun8i_dwmac_get_syscon_from_dev(struct device_node *node) ··· 1187 1192 plat_dat->bsp_priv = gmac; 1188 1193 plat_dat->init = sun8i_dwmac_init; 1189 1194 plat_dat->exit = sun8i_dwmac_exit; 1190 - plat_dat->setup = sun8i_dwmac_setup; 1195 + plat_dat->mac_setup = sun8i_dwmac_setup; 1191 1196 plat_dat->tx_fifo_size = 4096; 1192 1197 plat_dat->rx_fifo_size = 16384; 1193 1198
+10 -8
drivers/net/ethernet/stmicro/stmmac/hwif.c
··· 347 347 priv->estaddr = priv->ioaddr + EST_XGMAC_OFFSET; 348 348 } 349 349 350 - /* Check for HW specific setup first */ 351 - if (priv->plat->setup) { 352 - mac = priv->plat->setup(priv); 353 - needs_setup = false; 354 - } else { 355 - mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL); 356 - } 357 - 350 + mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL); 358 351 if (!mac) 359 352 return -ENOMEM; 353 + 354 + /* Check for HW specific setup first */ 355 + if (priv->plat->mac_setup) { 356 + ret = priv->plat->mac_setup(priv, mac); 357 + if (ret) 358 + return ret; 359 + 360 + needs_setup = false; 361 + } 360 362 361 363 spin_lock_init(&mac->irq_ctrl_lock); 362 364
+3 -1
include/linux/stmmac.h
··· 192 192 #define STMMAC_FLAG_EN_TX_LPI_CLK_PHY_CAP BIT(12) 193 193 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY BIT(13) 194 194 195 + struct mac_device_info; 196 + 195 197 struct plat_stmmacenet_data { 196 198 enum dwmac_core_type core_type; 197 199 int bus_id; ··· 268 266 void (*exit)(struct platform_device *pdev, void *priv); 269 267 int (*suspend)(struct device *dev, void *priv); 270 268 int (*resume)(struct device *dev, void *priv); 271 - struct mac_device_info *(*setup)(void *priv); 269 + int (*mac_setup)(void *priv, struct mac_device_info *mac); 272 270 int (*clks_config)(void *priv, bool enabled); 273 271 int (*crosststamp)(ktime_t *device, struct system_counterval_t *system, 274 272 void *ctx);