From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
linux-can@vger.kernel.org, kernel@pengutronix.de,
s.grosjean@peak-system.fr, stable@vger.kernel.org
Subject: Re: [PATCH net-next 16/23] can: peak_usb: register the netdevs only once all channels are set up
Date: Thu, 03 Dec 2026 23:12:18 +0000 [thread overview]
Message-ID: <179633953890.3146.16528120683494522758@kernel.org> (raw)
In-Reply-To: <20261202230853.2665144-17-mkl@pengutronix.de>
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
next prev parent reply other threads:[~2026-12-03 23:12 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 23:04 [PATCH net-next 0/23] pull-request: can-next 2026-12-03 Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 01/23] selftests: can: install net/lib.sh with the CAN tests Marc Kleine-Budde
2026-12-02 23:15 ` netdev-bot+sinfo
2026-12-02 23:04 ` [PATCH net-next 02/23] selftests: can: add J1939 test helper header and library Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 03/23] selftests: can: add J1939 base functional tests Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 04/23] selftests: can: add J1939 socket option and metadata tests Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 05/23] selftests: can: add J1939 addressing and concurrency tests Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 06/23] selftests: can: add J1939 wire-format tests against CAN_RAW Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 07/23] selftests: can: add J1939 TP/ETP multi-frame " Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 08/23] selftests: can: cover J1939 transport abort and timeout paths Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 09/23] selftests: can: check SO_J1939_PROMISC receive effect Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 10/23] can: peak_usb: fix missing CAN_ERR_FLAG when reporting error counters Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 11/23] can: peak_usb: harden PCAN-USB message validation Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 12/23] can: peak_usb: replace open-coded bitmask operations with bitops Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 13/23] can: peak_usb: harden channel handling in PCAN-USB FD Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 14/23] can: peak_usb: fix RX cursor desync for self-received RTR frames with SRR Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 15/23] can: peak_usb: reject records for unset channels in PCAN-USB Pro Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 16/23] can: peak_usb: register the netdevs only once all channels are set up Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko [this message]
2026-12-02 23:04 ` [PATCH net-next 17/23] can: peak_usb: validate the data length of PCAN-USB Pro CAN records Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 18/23] can: peak_usb: don't read past the message in PCAN-USB Pro decoders Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 19/23] can: peak_usb: dump undecodable URBs once and rate limit decode errors Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 20/23] can: peak_usb: don't return an uninitialized PCAN-USB CAN channel ID Marc Kleine-Budde
2026-12-03 23:12 ` netdev-bot+sashiko
2026-12-02 23:04 ` [PATCH net-next 21/23] can: peak_usb: pass the dev_num argument of PCAN-USB Pro GETDEVID Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 22/23] can: peak_usb: don't send uninitialized stack bytes to PCAN-USB devices Marc Kleine-Budde
2026-12-02 23:04 ` [PATCH net-next 23/23] can: peak_usb: don't send uninitialized heap bytes in restart commands Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179633953890.3146.16528120683494522758@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=s.grosjean@peak-system.fr \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox