Skip to contentSkip to conversation

net: ethernet: mtk_eth_soc: unregister net_devices in case of probe failure

PATCH Applied Lorenzo Bianconi 2 participants 2 messages Sep 16 – Sep 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 8a8a9e89f801 ("net: ethernet: mediatek: cleanup error path inside mtk_hw_init")
---
 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
index fd7a49ae88d0..2ea5dfe85539 100644
@@ -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]>
#1 lore raw
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 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.

[...]

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