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

net: mediatek: mtk_eth_sock: allocate dummy net_device dynamically

Embedding net_device into structures prohibits the usage of flexible
arrays in the net_device structure. For more details, see the discussion
at [1].

Un-embed the net_device from the private struct by converting it
into a pointer. Then use the leverage the new alloc_netdev_dummy()
helper to allocate and initialize dummy devices.

[1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/

Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Breno Leitao and committed by
David S. Miller
b209bd6d ec24c06e

+14 -5
+13 -4
drivers/net/ethernet/mediatek/mtk_eth_soc.c
··· 1710 1710 if (IS_ERR(pp)) 1711 1711 return pp; 1712 1712 1713 - err = __xdp_rxq_info_reg(xdp_q, &eth->dummy_dev, id, 1713 + err = __xdp_rxq_info_reg(xdp_q, eth->dummy_dev, id, 1714 1714 eth->rx_napi.napi_id, PAGE_SIZE); 1715 1715 if (err < 0) 1716 1716 goto err_free_pp; ··· 4188 4188 metadata_dst_free(eth->dsa_meta[i]); 4189 4189 } 4190 4190 4191 + free_netdev(eth->dummy_dev); 4192 + 4191 4193 return 0; 4192 4194 } 4193 4195 ··· 4985 4983 /* we run 2 devices on the same DMA ring so we need a dummy device 4986 4984 * for NAPI to work 4987 4985 */ 4988 - init_dummy_netdev(&eth->dummy_dev); 4989 - netif_napi_add(&eth->dummy_dev, &eth->tx_napi, mtk_napi_tx); 4990 - netif_napi_add(&eth->dummy_dev, &eth->rx_napi, mtk_napi_rx); 4986 + eth->dummy_dev = alloc_netdev_dummy(0); 4987 + if (!eth->dummy_dev) { 4988 + err = -ENOMEM; 4989 + dev_err(eth->dev, "failed to allocated dummy device\n"); 4990 + goto err_unreg_netdev; 4991 + } 4992 + netif_napi_add(eth->dummy_dev, &eth->tx_napi, mtk_napi_tx); 4993 + netif_napi_add(eth->dummy_dev, &eth->rx_napi, mtk_napi_rx); 4991 4994 4992 4995 platform_set_drvdata(pdev, eth); 4993 4996 schedule_delayed_work(&eth->reset.monitor_work, ··· 5000 4993 5001 4994 return 0; 5002 4995 4996 + err_unreg_netdev: 4997 + mtk_unreg_dev(eth); 5003 4998 err_deinit_ppe: 5004 4999 mtk_ppe_deinit(eth); 5005 5000 mtk_mdio_cleanup(eth);
+1 -1
drivers/net/ethernet/mediatek/mtk_eth_soc.h
··· 1242 1242 spinlock_t page_lock; 1243 1243 spinlock_t tx_irq_lock; 1244 1244 spinlock_t rx_irq_lock; 1245 - struct net_device dummy_dev; 1245 + struct net_device *dummy_dev; 1246 1246 struct net_device *netdev[MTK_MAX_DEVS]; 1247 1247 struct mtk_mac *mac[MTK_MAX_DEVS]; 1248 1248 int irq[3];