]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: mana: Skip redundant detach on already-detached port
authorDipayaan Roy <dipayanroy@linux.microsoft.com>
Mon, 25 May 2026 08:08:25 +0000 (01:08 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 28 May 2026 23:33:42 +0000 (16:33 -0700)
When mana_per_port_queue_reset_work_handler() runs after a previous
detach succeeded but attach failed, the port is left in a detached
state with apc->tx_qp and apc->rxqs already freed. Calling
mana_detach() again unconditionally leads to NULL pointer dereferences
during queue teardown.

Add an early exit in mana_detach() when the port is already in
detached state (!netif_device_present) for non-close callers, making
it safe to call idempotently. This allows the queue reset handler and
other recovery paths to simply retry mana_attach() without redundant
teardown.

Fixes: 3b194343c250 ("net: mana: Implement ndo_tx_timeout and serialize queue resets per port.")
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Dipayaan Roy <dipayanroy@linux.microsoft.com>
Link: https://patch.msgid.link/20260525081129.1230035-3-dipayanroy@linux.microsoft.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/microsoft/mana/mana_en.c

index 9e7e4bf526bf6d00c355c689bc5d18710d62bfc4..c9b1df1ed1098ca7fd63f6df17c18cc8a09d14cb 100644 (file)
@@ -3350,6 +3350,12 @@ int mana_detach(struct net_device *ndev, bool from_close)
 
        ASSERT_RTNL();
 
+       /* If already detached (indicates detach succeeded but attach failed
+        * previously). Now skip mana detach and just retry mana_attach.
+        */
+       if (!from_close && !netif_device_present(ndev))
+               return 0;
+
        apc->port_st_save = apc->port_is_up;
        apc->port_is_up = false;