can: mcp251xfd: mcp251xfd_remove(): fix order of unregistration calls
authorMarc Kleine-Budde <mkl@pengutronix.de>
Fri, 2 May 2025 14:13:44 +0000 (16:13 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Tue, 6 May 2025 13:45:46 +0000 (15:45 +0200)
If a driver is removed, the driver framework invokes the driver's
remove callback. A CAN driver's remove function calls
unregister_candev(), which calls net_device_ops::ndo_stop further down
in the call stack for interfaces which are in the "up" state.

With the mcp251xfd driver the removal of the module causes the
following warning:

| WARNING: CPU: 0 PID: 352 at net/core/dev.c:7342 __netif_napi_del_locked+0xc8/0xd8

as can_rx_offload_del() deletes the NAPI, while it is still active,
because the interface is still up.

To fix the warning, first unregister the network interface, which
calls net_device_ops::ndo_stop, which disables the NAPI, and then call
can_rx_offload_del().

Fixes: 55e5b97f003e ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20250502-can-rx-offload-del-v1-1-59a9b131589d@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

index 064d81c724f4c3cdbec532a78ac3654653b07183..c30b04f8fc0df80357fdc16043b6e195457f3eac 100644 (file)
@@ -2198,8 +2198,8 @@ static void mcp251xfd_remove(struct spi_device *spi)
        struct mcp251xfd_priv *priv = spi_get_drvdata(spi);
        struct net_device *ndev = priv->ndev;
 
-       can_rx_offload_del(&priv->offload);
        mcp251xfd_unregister(priv);
+       can_rx_offload_del(&priv->offload);
        spi->max_speed_hz = priv->spi_max_speed_hz_orig;
        free_candev(ndev);
 }