* [PATCH v3] net: lan966x: avoid unregistering netdev on register failure
@ 2026-05-06 12:43 Myeonghun Pak
2026-05-08 23:40 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Myeonghun Pak @ 2026-05-06 12:43 UTC (permalink / raw)
To: Horatiu Vultur, UNGLinuxDriver, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Ijae Kim
Cc: Myeonghun Pak, netdev, linux-kernel
lan966x_probe_port() stores the newly allocated net_device in the
port before calling register_netdev(). If register_netdev() fails,
the probe error path calls lan966x_cleanup_ports(), which sees
port->dev and calls unregister_netdev() for a device that was never
registered.
Destroy the phylink instance created for this port and clear port->dev
before returning the registration error. The common cleanup path now skips
ports without port->dev before reaching the registered netdev cleanup, so
it only handles ports that reached the registered-netdev lifetime.
This also avoids treating an uninitialized FDMA netdev and the failed port
as a NULL == NULL match in the common cleanup path.
Fixes: d28d6d2e37d1 ("net: lan966x: add port module support")
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
Changes in v3:
- Make lan966x_cleanup_ports() skip ports without port->dev, so the
common cleanup path does not run registered-netdev, XDP, FDMA, or
phylink cleanup for a port whose netdev registration failed.
- Keep the register_netdev() failure path responsible for destroying the
newly created phylink and clearing port->dev before returning.
Changes in v2:
- Require port->dev to be non-NULL before calling the FDMA netdev cleanup
path, avoiding a NULL == NULL match when register_netdev() fails before
FDMA NAPI has been initialized.
drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
index 47752d3fde..1179a6e127 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
@@ -749,11 +749,10 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x)
for (p = 0; p < lan966x->num_phys_ports; p++) {
port = lan966x->ports[p];
- if (!port)
+ if (!port || !port->dev)
continue;
- if (port->dev)
- unregister_netdev(port->dev);
+ unregister_netdev(port->dev);
lan966x_xdp_port_deinit(port);
if (lan966x->fdma && lan966x->fdma_ndev == port->dev)
@@ -873,6 +872,9 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p,
err = register_netdev(dev);
if (err) {
dev_err(lan966x->dev, "register_netdev failed\n");
+ phylink_destroy(phylink);
+ port->phylink = NULL;
+ port->dev = NULL;
return err;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v3] net: lan966x: avoid unregistering netdev on register failure
2026-05-06 12:43 [PATCH v3] net: lan966x: avoid unregistering netdev on register failure Myeonghun Pak
@ 2026-05-08 23:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-08 23:40 UTC (permalink / raw)
To: Myeonghun Pak
Cc: horatiu.vultur, UNGLinuxDriver, andrew+netdev, davem, edumazet,
kuba, pabeni, ae878000, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 6 May 2026 21:43:11 +0900 you wrote:
> lan966x_probe_port() stores the newly allocated net_device in the
> port before calling register_netdev(). If register_netdev() fails,
> the probe error path calls lan966x_cleanup_ports(), which sees
> port->dev and calls unregister_netdev() for a device that was never
> registered.
>
> Destroy the phylink instance created for this port and clear port->dev
> before returning the registration error. The common cleanup path now skips
> ports without port->dev before reaching the registered netdev cleanup, so
> it only handles ports that reached the registered-netdev lifetime.
>
> [...]
Here is the summary with links:
- [v3] net: lan966x: avoid unregistering netdev on register failure
https://git.kernel.org/netdev/net/c/c4f3d6eb1fcf
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-08 23:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06 12:43 [PATCH v3] net: lan966x: avoid unregistering netdev on register failure Myeonghun Pak
2026-05-08 23:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox