Netdev List
 help / color / mirror / Atom feed
* [PATCH net] can: esd_usb: kill anchored URBs before freeing netdevs
@ 2026-07-09 10:46 Fan Wu
  2026-07-09 15:17 ` Jagielski, Jedrzej
  2026-07-09 16:41 ` [PATCH net v2] " Fan Wu
  0 siblings, 2 replies; 4+ messages in thread
From: Fan Wu @ 2026-07-09 10:46 UTC (permalink / raw)
  To: linux-can
  Cc: frank.jungclaus, socketcan, mkl, mailhol, netdev, linux-kernel,
	Fan Wu, stable

esd_usb_disconnect() frees each CAN netdev with free_candev() inside
its per-netdev loop and only calls unlink_all_urbs(dev) afterwards.
The per-netdev private data (struct esd_usb_net_priv) is embedded in
the net_device allocation returned by alloc_candev(), so once
free_candev() has run, dev->nets[i] points to freed memory.
unlink_all_urbs() then dereferences the freed dev->nets[i] to kill the
per-netdev TX anchor (usb_kill_anchored_urbs(&priv->tx_submitted)),
clear active_tx_jobs, and reset priv->tx_contexts[].

Reorder the teardown so the anchored URBs are killed before the netdevs
are freed, matching other CAN/USB drivers in the same directory such as
ems_usb, usb_8dev and mcba_usb, which unregister, then unlink, then
free: unregister the netdevs first (which stops their TX queues), call
unlink_all_urbs(dev) once, then free the netdevs.

This issue was found by an in-house static analysis tool.

Fixes: 96d8e90382dc336b5de401164597edfdc2e8d9f1 ("can: Add driver for esd CAN-USB/2 device")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.5
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
 drivers/net/can/usb/esd_usb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index d257440fa..f41d4a0d1 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -1390,10 +1390,13 @@ static void esd_usb_disconnect(struct usb_interface *intf)
 				netdev = dev->nets[i]->netdev;
 				netdev_info(netdev, "unregister\n");
 				unregister_netdev(netdev);
-				free_candev(netdev);
 			}
 		}
 		unlink_all_urbs(dev);
+		for (i = 0; i < dev->net_count; i++) {
+			if (dev->nets[i])
+				free_candev(dev->nets[i]->netdev);
+		}
 		kfree(dev);
 	}
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH net] can: esd_usb: kill anchored URBs before freeing netdevs
  2026-07-09 10:46 [PATCH net] can: esd_usb: kill anchored URBs before freeing netdevs Fan Wu
@ 2026-07-09 15:17 ` Jagielski, Jedrzej
  2026-07-09 16:41 ` [PATCH net v2] " Fan Wu
  1 sibling, 0 replies; 4+ messages in thread
From: Jagielski, Jedrzej @ 2026-07-09 15:17 UTC (permalink / raw)
  To: Fan Wu, linux-can@vger.kernel.org
  Cc: frank.jungclaus@esd.eu, socketcan@esd.eu, mkl@pengutronix.de,
	mailhol@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org

From: Fan Wu <fanwu01@zju.edu.cn> 
Sent: Thursday, July 9, 2026 12:46 PM

>esd_usb_disconnect() frees each CAN netdev with free_candev() inside
>its per-netdev loop and only calls unlink_all_urbs(dev) afterwards.
>The per-netdev private data (struct esd_usb_net_priv) is embedded in
>the net_device allocation returned by alloc_candev(), so once
>free_candev() has run, dev->nets[i] points to freed memory.
>unlink_all_urbs() then dereferences the freed dev->nets[i] to kill the
>per-netdev TX anchor (usb_kill_anchored_urbs(&priv->tx_submitted)),
>clear active_tx_jobs, and reset priv->tx_contexts[].
>
>Reorder the teardown so the anchored URBs are killed before the netdevs
>are freed, matching other CAN/USB drivers in the same directory such as
>ems_usb, usb_8dev and mcba_usb, which unregister, then unlink, then
>free: unregister the netdevs first (which stops their TX queues), call
>unlink_all_urbs(dev) once, then free the netdevs.
>
>This issue was found by an in-house static analysis tool.
>
>Fixes: 96d8e90382dc336b5de401164597edfdc2e8d9f1 ("can: Add driver for esd CAN-USB/2 device")

Hi Fan,

no need to put whole SHA, 12 first chars is enough




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net v2] can: esd_usb: kill anchored URBs before freeing netdevs
  2026-07-09 10:46 [PATCH net] can: esd_usb: kill anchored URBs before freeing netdevs Fan Wu
  2026-07-09 15:17 ` Jagielski, Jedrzej
@ 2026-07-09 16:41 ` Fan Wu
  2026-07-17  9:50   ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Fan Wu @ 2026-07-09 16:41 UTC (permalink / raw)
  To: linux-can
  Cc: frank.jungclaus, socketcan, mkl, mailhol, jedrzej.jagielski,
	netdev, linux-kernel, Fan Wu, stable

esd_usb_disconnect() frees each CAN netdev with free_candev() inside
its per-netdev loop and only calls unlink_all_urbs(dev) afterwards.
The per-netdev private data (struct esd_usb_net_priv) is embedded in
the net_device allocation returned by alloc_candev(), so once
free_candev() has run, dev->nets[i] points to freed memory.
unlink_all_urbs() then dereferences the freed dev->nets[i] to kill the
per-netdev TX anchor (usb_kill_anchored_urbs(&priv->tx_submitted)),
clear active_tx_jobs, and reset priv->tx_contexts[].

Reorder the teardown so the anchored URBs are killed before the netdevs
are freed, matching other CAN/USB drivers in the same directory such as
ems_usb, usb_8dev and mcba_usb, which unregister, then unlink, then
free: unregister the netdevs first (which stops their TX queues), call
unlink_all_urbs(dev) once, then free the netdevs.

This issue was found by an in-house static analysis tool.

Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.5
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
Changes in v2: shorten the Fixes: tag to the abbreviated 12-char SHA
per Jedrzej Jagielski ("no need to put whole SHA, 12 first chars is
enough").

v1: https://lore.kernel.org/netdev/20260709104620.133765-1-fanwu01@zju.edu.cn/
 drivers/net/can/usb/esd_usb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index d257440fa..f41d4a0d1 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -1390,10 +1390,13 @@ static void esd_usb_disconnect(struct usb_interface *intf)
 				netdev = dev->nets[i]->netdev;
 				netdev_info(netdev, "unregister\n");
 				unregister_netdev(netdev);
-				free_candev(netdev);
 			}
 		}
 		unlink_all_urbs(dev);
+		for (i = 0; i < dev->net_count; i++) {
+			if (dev->nets[i])
+				free_candev(dev->nets[i]->netdev);
+		}
 		kfree(dev);
 	}
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] can: esd_usb: kill anchored URBs before freeing netdevs
  2026-07-09 16:41 ` [PATCH net v2] " Fan Wu
@ 2026-07-17  9:50   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-07-17  9:50 UTC (permalink / raw)
  To: Fan Wu
  Cc: linux-can, frank.jungclaus, socketcan, mkl, mailhol,
	jedrzej.jagielski, netdev, linux-kernel, stable

Hello:

This patch was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Thu,  9 Jul 2026 16:41:59 +0000 you wrote:
> esd_usb_disconnect() frees each CAN netdev with free_candev() inside
> its per-netdev loop and only calls unlink_all_urbs(dev) afterwards.
> The per-netdev private data (struct esd_usb_net_priv) is embedded in
> the net_device allocation returned by alloc_candev(), so once
> free_candev() has run, dev->nets[i] points to freed memory.
> unlink_all_urbs() then dereferences the freed dev->nets[i] to kill the
> per-netdev TX anchor (usb_kill_anchored_urbs(&priv->tx_submitted)),
> clear active_tx_jobs, and reset priv->tx_contexts[].
> 
> [...]

Here is the summary with links:
  - [net,v2] can: esd_usb: kill anchored URBs before freeing netdevs
    https://git.kernel.org/netdev/net/c/c43122fef328

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] 4+ messages in thread

end of thread, other threads:[~2026-07-17  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-09 10:46 [PATCH net] can: esd_usb: kill anchored URBs before freeing netdevs Fan Wu
2026-07-09 15:17 ` Jagielski, Jedrzej
2026-07-09 16:41 ` [PATCH net v2] " Fan Wu
2026-07-17  9:50   ` 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