* Re: [PATCH net-next 16/23] can: peak_usb: register the netdevs only once all channels are set up
[not found] <20261202230853.2665144-17-mkl@pengutronix.de>
@ 2026-12-03 23:12 ` netdev-bot+sashiko
0 siblings, 0 replies; only message in thread
From: netdev-bot+sashiko @ 2026-12-03 23:12 UTC (permalink / raw)
To: mkl; +Cc: netdev, davem, kuba, linux-can, kernel, s.grosjean, stable
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] After this patch, pcan_usb_get_can_channel_id() carries a comment
saying it uses dev_xxx() instead of netdev_xxx() because it is now…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a use-
after-free in the same probe/disconnect lifecycle the patch reworks.
--
can: peak_usb: register the netdevs only once all channels are set up
This commit moves register_candev() out of peak_usb_create_dev() and into
peak_usb_probe(). The netdevs are now registered only after dev_init(),
dev_set_bus() and dev_get_can_channel_id() have run for every channel of the
interface, and peak_usb_disconnect() unregisters only the netdevs flagged
with PCAN_USB_STATE_REGISTERED.
Link: https://patch.msgid.link/20261126-canfd_check_channel_idx-v9-7-abe0099b4585@peak-system.fr
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
> index 90f69afcba974..451d084215049 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
> @@ -390,9 +390,12 @@ static int pcan_usb_get_can_channel_id(struct peak_usb_device *dev, u32 *can_ch_
> int err;
>
> err = pcan_usb_wait_rsp(dev, PCAN_USB_CMD_DEVID, PCAN_USB_GET, args);
> + /* explicit use of dev_xxx() instead of netdev_xxx() here: this is
> + * also called during probe, before the netdev is registered.
> + */
> if (err)
> - netdev_err(dev->netdev, "getting can channel id failure: %d\n", err);
> -
> + dev_err(dev->netdev->dev.parent,
> + "getting can channel id failure: %d\n", err);
> else
> *can_ch_id = args[0];
[Severity: Low]
The new comment says dev_xxx() is used here because this runs during probe,
before the netdev is registered. Shouldn't the same apply to the helpers on
this path?
pcan_usb_wait_rsp(), which is called just above, and pcan_usb_send_cmd()
still log through netdev_err(dev->netdev, ...):
pcan_usb_wait_rsp() {
...
if (err)
netdev_err(dev->netdev,
"waiting rsp f=0x%x n=0x%x failure: %d\n", f, n, err);
...
}
The same applies to pcan_usb_pro_send_req() (netdev_info),
pcan_usb_pro_send_cmd() and pcan_usb_pro_wait_rsp() (netdev_err) in
pcan_usb_pro.c, and to pcan_usb_fd_send_cmd() (netdev_err) in pcan_usb_fd.c.
With this patch, all of the following run in peak_usb_create_dev() before
peak_usb_probe() calls register_candev():
dev_init():
pcan_usb_init()->pcan_usb_get_serial()->pcan_usb_wait_rsp()
pcan_usb_pro_init()
pcan_usb_fd_init()
dev_set_bus(dev, 0)
dev_get_can_channel_id()
If a USB command fails during probe, __netdev_printk() prints the message
with the "can%d" template name and tags it "(unnamed net_device)
(uninitialized)".
Could these helpers be converted too, so the code matches the new comment?
They are still unconverted at the end of the series.
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> index f5c39b43b0fa1..e5198ec5c760d 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
[ ... ]
> @@ -1078,11 +1059,15 @@ static void peak_usb_disconnect(struct usb_interface *intf)
> for (dev = usb_get_intfdata(intf); dev; dev = dev_prev_siblings) {
> struct net_device *netdev = dev->netdev;
> char name[IFNAMSIZ];
> + bool registered;
>
> dev_prev_siblings = dev->prev_siblings;
> strscpy(name, netdev->name, IFNAMSIZ);
>
> - unregister_candev(netdev);
> + /* on probe error, some netdevs may not be registered yet */
> + registered = test_bit(PCAN_USB_STATE_REGISTERED, &dev->state);
> + if (registered)
> + unregister_candev(netdev);
>
> kfree(dev->cmd_buf);
> dev->next_siblings = NULL;
> @@ -1090,7 +1075,8 @@ static void peak_usb_disconnect(struct usb_interface *intf)
> dev->adapter->dev_free(dev);
>
> free_candev(netdev);
[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but it is in
the probe/disconnect code this patch reworks. Can the PCAN-USB restart_timer
still fire after free_candev() has freed it?
pcan_usb_init() calls timer_setup(&pdev->restart_timer, pcan_usb_restart, 0).
The timer lives in struct pcan_usb, which is the netdev private area.
A CAN restart can come from bus-off with restart-ms set, or from "ip link set
canX type can restart". In that case
peak_usb_set_mode()->peak_usb_restart()->pcan_usb_restart_async() submits a
URB that is not anchored. Its completion arms the timer unconditionally, even
on -ESHUTDOWN or -ENOENT:
pcan_usb_restart_pending() {
...
mod_timer(&pdev->restart_timer,
jiffies + msecs_to_jiffies(PCAN_USB_STARTUP_TIMEOUT));
...
}
Nothing under drivers/net/can/usb/peak_usb/ cancels this timer. The pcan_usb
adapter has no dev_free, dev_stop or dev_exit callback, and
peak_usb_ndo_stop() doesn't touch the timer.
Suppose the device is unplugged or unbound (sysfs unbind, rmmod) while the
restart URB is in flight or within the 10 ms timer window. Then either
pcan_usb_restart_pending() calls mod_timer() on freed memory, or
pcan_usb_restart() runs from the timer softirq on freed memory:
pcan_usb_restart()
peak_usb_restart_complete(dev)
writes dev->can.state
netif_wake_queue() on the freed netdev
Should the timer be shut down, and the restart URB killed, before
free_candev() runs here? This is still present at the end of the series.
> - dev_info(&intf->dev, "%s removed\n", name);
> + if (registered)
> + dev_info(&intf->dev, "%s removed\n", name);
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202230853.2665144-2-mkl%40pengutronix.de
^ permalink raw reply [flat|nested] only message in thread