Article View: linux.kernel.netdev
Article #26600Re: [PATCH net-next 16/23] can: peak_usb: register the netdevs only once all channels are set up
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 23:12
Date: Thu, 03 Dec 2026 23:12
158 lines
13729 bytes
13729 bytes
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
Technical Details
Message-ID:
<179633953890.3146.16528120683494522758@kernel.org>Path:
mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-nl.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376900-linux-kernel-netdev=dewy.ruReferences:
<20261202230853.2665144-17-mkl@pengutronix.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-nl.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376900-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <179633953890.3146.16528120683494522758@kernel.org> References: <20261202230853.2665144-17-mkl@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2624857"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:L14X3TvOCvwtm5SsxXMB0w9xTqg= sha256:tkeLiJpLLtPKjA7GuxbRFe5zWqNvaxs7r+91HJUgcUQ= sha1:CiBSvhNZ4dw5e7V85AyDEXo1gg0= sha256:delZVIZIKBQYym0RKHE0OpITGloWMI7MiLmuuN3okSs= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 82FF6117A5F; Fri, 4 Dec 2026 02:12:38 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.74 X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id odvOBqtHL79B; Fri, 4 Dec 2026 02:12:35 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376900-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 9E6B7117A32; Fri, 4 Dec 2026 02:12:25 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 33E4B23FEA; Thu, 3 Dec 2026 23:12:21 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796339541; b=DAn75pvWOZFsrvlSsbPPpce4Is3i49T/agfa8MG3+LtOqJnApoVDQj8XhMtm9iyteMfZ 3gCzIbh58D/7dgvI6YcSaKuFhTJo6AeunCHbZuJg9ZyxYZ1mFVyewsS/98hoRkFrrFH8c UbMQZDIxjKXFjvUGYK+gt6kjjWGYQIPJ9cuu0GC3iri7MAh+sVwPKoGdCXZ3/rb/bcGVp femi7AfwwIWWXYi2uZBZSNvfZC9V40u/7uzJhpg0Sx0+0J08RcHcg6P8e9tDMGpR801QQ FOMKPJDnDqnRs86uFzor4zEoGauP2gkS14C01/srZ+l1lbVV7luBfs5gTQr+tXmLnhA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796339541; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=vuWaLKckY6JYPiA28Qg2WzEMDkuIxjHv3cg9QZGWYQI=; b=VuXWT29FOg4G4qBA2Jvg+5UfSeRwEBXFE9f+uqsQL4nrsFZI1zLHzZ2mVAPUel8YgzMB NMwEH3esmCRBsZOTw6RF9+Fceuvv0wde0kLFhiB1pLB6jdYKQqWILatCyuHTV9IiRR7ik wGH75J91T1DKR4jUGlX7zimt3edfw2GiQF1OKq1IEzkvxK4Thtu8OunOh7ZA+lrAKoqln bL9mHxZd2X80FtGzgziHi0TrjnonuBO+1kfCbrfsf5wT8VM15rg9Up0RX1mXweo1wllrD gseaRuERK5lYGS1mzZeIDsYHidQmweArc6C4rfJrYiv+LkT/ybTHFak5YOLAvPKzimg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IR6yUm3s; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9CE3606A33D; Thu, 3 Dec 2026 23:12:20 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IR6yUm3s X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796339540; b=jJMEnZWEfqNHfSm04+ur1v8c9DW3ai6vVYLMbu20kho7LhweCoir8WnDaB24AG4kwmjb zvyRkKN+nEyfbA+zbVp57jkZWJgJXfwpC2Mpp8hKjsqT5Oo5gEB2vBPEvXKyPkz/V5HKr dIi5fnLvP9jugtFqBI0rKbUBWYP5ah2tRSB9Ihf5PU2KjkwYYiYac6+gchXu9TwFPHwjv ITipMogyZy5WixTGRAu0Peqvv1BVpmwcq1ilvEc/TBI2SQZ7hFMuv6ulhW0aOg2tQqT1E kSeTtWUGt6FH0GAdUQN2HAcOyG9B+zUnOgEq2KT9jpSR43LmawT1KEi+bqyD8+dqbfQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796339540; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=vuWaLKckY6JYPiA28Qg2WzEMDkuIxjHv3cg9QZGWYQI=; b=B5S3s5AqPfStzLMIahoFXZ3cLdK04r3hJY6At57uRfz0A3eXjCnhvtz6b4DLMdr/d8iS wTup6FDixGNsy84hFN8P1ePKy6UOa4AWa205qlfnBam9JbkT9cAYREvM1gPvwPOHV1Cop I9XnIn2MbKtULyqH+7ZAv6CuRy05LcRQYttMd8HhpiQmzvzrA/e3f8U3h3DLWxd/tBP5Y 8fWks00knSS4uF77Ptr6nkUVB7g6122GI8mG/qcnUUjZtRxtfcVn1zKno8ePBOcDF8OH0 kpBWt+aT+5tzgTGQgz4WIyl+rOsf/z+1foXfoWiZajcU4h1SXFirGsIIchKqGGytBBw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IR6yUm3s; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14FA9606A330; Thu, 3 Dec 2026 23:12:19 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EC271F000C2; Thu, 3 Dec 2026 23:12:19 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796339539; bh=vuWaLKckY6JYPiA28Qg2WzEMDkuIxjHv3cg9QZGWYQI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=IR6yUm3sozUcr6a8CwxCZA96SmNtuOrKA808rlvl2Pr1zRmnmN/b4N9UF7YyEMuww ch6m3cFcxc9gDsWBSE2iBpvA2F33zH8Ul7y+FVGJNOWJeext69RYKOUokmJ5ivZOI6 ea3eN2AcLBUeoXKhUzvlVvRkKrqDwxTenSj8VrhPK7ALk07XjqujqSgoJqLfSrgCRH mO/rLvLz0ZcGTkZrthNi0iD7//eQySAotUPIl5N7PolmylS5wlB/O0Xd58L/z+gaqw fjm4b4A4naLazK/wIPpAXodVK2iZOaWGoJ0gx4Sg2bZPsRgjodNNDbK5sPyqzUwB1W Tzm2u9CZoxNwA== X-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 X-In-Reply-To: <20261202230853.2665144-17-mkl@pengutronix.de> X-sashiko-severity: Low X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list