Commit b209bd6d authored by Breno Leitao's avatar Breno Leitao Committed by David S. Miller
Browse files

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: default avatarBreno Leitao <leitao@debian.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ec24c06e
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -1710,7 +1710,7 @@ static struct page_pool *mtk_create_page_pool(struct mtk_eth *eth,
	if (IS_ERR(pp))
		return pp;

	err = __xdp_rxq_info_reg(xdp_q, &eth->dummy_dev, id,
	err = __xdp_rxq_info_reg(xdp_q, eth->dummy_dev, id,
				 eth->rx_napi.napi_id, PAGE_SIZE);
	if (err < 0)
		goto err_free_pp;
@@ -4188,6 +4188,8 @@ static int mtk_free_dev(struct mtk_eth *eth)
		metadata_dst_free(eth->dsa_meta[i]);
	}

	free_netdev(eth->dummy_dev);

	return 0;
}

@@ -4983,9 +4985,14 @@ static int mtk_probe(struct platform_device *pdev)
	/* we run 2 devices on the same DMA ring so we need a dummy device
	 * for NAPI to work
	 */
	init_dummy_netdev(&eth->dummy_dev);
	netif_napi_add(&eth->dummy_dev, &eth->tx_napi, mtk_napi_tx);
	netif_napi_add(&eth->dummy_dev, &eth->rx_napi, mtk_napi_rx);
	eth->dummy_dev = alloc_netdev_dummy(0);
	if (!eth->dummy_dev) {
		err = -ENOMEM;
		dev_err(eth->dev, "failed to allocated dummy device\n");
		goto err_unreg_netdev;
	}
	netif_napi_add(eth->dummy_dev, &eth->tx_napi, mtk_napi_tx);
	netif_napi_add(eth->dummy_dev, &eth->rx_napi, mtk_napi_rx);

	platform_set_drvdata(pdev, eth);
	schedule_delayed_work(&eth->reset.monitor_work,
@@ -4993,6 +5000,8 @@ static int mtk_probe(struct platform_device *pdev)

	return 0;

err_unreg_netdev:
	mtk_unreg_dev(eth);
err_deinit_ppe:
	mtk_ppe_deinit(eth);
	mtk_mdio_cleanup(eth);
+1 −1
Original line number Diff line number Diff line
@@ -1242,7 +1242,7 @@ struct mtk_eth {
	spinlock_t			page_lock;
	spinlock_t			tx_irq_lock;
	spinlock_t			rx_irq_lock;
	struct net_device		dummy_dev;
	struct net_device		*dummy_dev;
	struct net_device		*netdev[MTK_MAX_DEVS];
	struct mtk_mac			*mac[MTK_MAX_DEVS];
	int				irq[3];