net: ethernet: mtk_eth_soc: unregister net_devices in case of probe failure
Subsystems (4)
PATCH 1/1 net: ethernet: mtk_eth_soc: unregister net_devices in case of probe failure
If register_netdev() fails for one of the MTK_MAX_DEVS devices in mtk_probe(), the error path jumps to err_deinit_ppe, skipping mtk_unreg_dev(). The previously registered net_devices are then freed by mtk_free_dev() while still in NETREG_REGISTERED state, hitting the BUG_ON(dev->reg_state != NETREG_UNREGISTERED).
Route the register_netdev() failure to err_unreg_netdev so the net_devices registered so far are properly unregistered before being freed.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -1
@@ -4509,6 +4509,10 @@ static int mtk_unreg_dev(struct mtk_eth *eth) mac =netdev_priv (eth->netdev[i]);if (MTK_HAS_CAPS (eth->soc->caps,MTK_QDMA ))unregister_netdevice_notifier (&mac->device_notifier); + +if (eth->netdev[i]->reg_state !=NETREG_REGISTERED ) +continue ; +unregister_netdev (eth->netdev[i]); }
@@ -5344,7 +5348,7 @@ static int mtk_probe(struct platform_device *pdev) err =register_netdev (eth->netdev[i]);if (err) {dev_err (eth->dev,"error bringing up device\n" ); - goto err_deinit_ppe; + goto err_unreg_netdev; }else netif_info(eth, probe, eth->netdev[i], "mediatek frame engine at 0x%08lx, irq %d\n",
---
base-commit: ceac0de741bfb47ca255eee075257b3bb31f0651
change-id: 20260916-mtk_eth_soc-netdev-fix-a25ef3e54fe0
Best regards,
Signature · 1 line
Lorenzo Bianconi <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 16 Sep 2026 15:30:13 +0200 you wrote:
If
register_netdev()fails for one of theMTK_MAX_DEVSdevices inmtk_probe(), the error path jumps toerr_deinit_ppe, skippingmtk_unreg_dev(). The previously registerednet_devicesare then freed bymtk_free_dev()while still inNETREG_REGISTEREDstate, hitting theBUG_ON(dev->reg_state != NETREG_UNREGISTERED).Route the
register_netdev()failure toerr_unreg_netdevso thenet_devicesregistered so far are properly unregistered before being freed.[...]
Here is the summary with links:
- [net] net: ethernet: mtk_eth_soc: unregister net_devices in case of probe failure
https://git.kernel.org/netdev/net/c/310d1ac61a4d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html