* [PATCH v2] net: lan966x: avoid unregistering netdev on register failure
@ 2026-05-02 5:07 Myeonghun Pak
2026-05-04 12:33 ` Andrew Lunn
0 siblings, 1 reply; 2+ messages in thread
From: Myeonghun Pak @ 2026-05-02 5:07 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, matching the existing guard
used by the common cleanup path. Also require port->dev to be non-NULL
before matching it against the FDMA netdev, so the error path cannot treat
an uninitialized FDMA netdev and a failed port as a valid match.
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 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 | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
index 47752d3fde..22c496f588 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
@@ -756,7 +756,7 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x)
unregister_netdev(port->dev);
lan966x_xdp_port_deinit(port);
- if (lan966x->fdma && lan966x->fdma_ndev == port->dev)
+ if (lan966x->fdma && port->dev && lan966x->fdma_ndev == port->dev)
lan966x_fdma_netdev_deinit(lan966x, port->dev);
if (port->phylink) {
@@ -873,6 +873,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 v2] net: lan966x: avoid unregistering netdev on register failure
2026-05-02 5:07 [PATCH v2] net: lan966x: avoid unregistering netdev on register failure Myeonghun Pak
@ 2026-05-04 12:33 ` Andrew Lunn
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2026-05-04 12:33 UTC (permalink / raw)
To: Myeonghun Pak
Cc: Horatiu Vultur, UNGLinuxDriver, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Ijae Kim, netdev,
linux-kernel
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> @@ -756,7 +756,7 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x)
> unregister_netdev(port->dev);
>
> lan966x_xdp_port_deinit(port);
> - if (lan966x->fdma && lan966x->fdma_ndev == port->dev)
> + if (lan966x->fdma && port->dev && lan966x->fdma_ndev == port->dev)
> lan966x_fdma_netdev_deinit(lan966x, port->dev);
>
> if (port->phylink) {
Maybe this is better?
port = lan966x->ports[p];
if (!port || port->dev)
continue;
unregister_netdev(port->dev);
Andrew
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-04 12:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-02 5:07 [PATCH v2] net: lan966x: avoid unregistering netdev on register failure Myeonghun Pak
2026-05-04 12:33 ` Andrew Lunn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox