Linux CAN drivers development
 help / color / mirror / Atom feed
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,
	shuangpeng.kernel@gmail.com, stable@vger.kernel.org,
	vadim.fedorenko@linux.dev
Subject: Re: [PATCH net-next 1/9] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev()
Date: Tue, 01 Dec 2026 09:41:29 +0000	[thread overview]
Message-ID: <179611808903.3146.10926780520247936704@kernel.org> (raw)
In-Reply-To: <20261130092003.1946901-2-mkl@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] This patch moves register_candev() out of gs_make_candev()
  into a second loop in gs_usb_probe().

--

can: gs_usb: gs_usb_probe(): init netdev completely before register_candev()

This patch takes register_candev() out of gs_make_candev(). The probe
routine now allocates and fully initializes every CAN channel first, then
registers them all in a second loop. unregister_candev() moves out of
gs_destroy_candev() into gs_usb_disconnect() and the probe error paths.

Link: https://patch.msgid.link/20261130-gs_usb-fixes-v12-1-9ba1f84c179a@pengutronix.de

> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 15f28833f2deb..965151ab50a1e 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c

[ ... ]

> @@ -1621,7 +1605,37 @@ static int gs_usb_probe(struct usb_interface *intf,
>  		parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx);
>  	}
>  
> +	for (i = 0; i < icount; i++) {
> +		struct gs_can *dev = parent->canch[i];
> +
> +		rc = register_candev(dev->netdev);

[Severity: Medium]
With this ordering, every parent->canch[i] is non-NULL before any channel
is registered. Once register_candev() returns for channel 0, userspace can
open can0 while canch[1..n] are still unregistered.

Opening the first channel submits all of the shared bulk-IN URBs:

gs_can_open() {
    ...
	if (!parent->active_channels) {
		...
		for (i = 0; i < GS_MAX_RX_URBS; i++) {
			...
}

Suppose the device sends a frame for a channel that is not registered yet,
inside this window. What happens in gs_usb_receive_bulk_callback()?

	dev = parent->canch[hf->channel];

	netdev = dev->netdev;
	stats = &netdev->stats;

	if (!netif_device_present(netdev))
		return;

Only register_netdevice() sets __LINK_STATE_PRESENT, so the unregistered
netdev looks detached. The bare return skips the resubmit_urb label. USB
core has already unanchored the URB, so it is never resubmitted.

Could each such frame permanently remove one URB from the shared RX pool?
If enough of them arrive, would reception stop on all channels until every
channel is closed and reopened?

The window covers the rest of gs_can_open(), including its control
transfers, which run under RTNL. register_candev() for the next channel
also has to wait for RTNL.

Triggering this needs a device that sends frames for a channel the host has
not started. One example is firmware that keeps channel state across
re-enumeration, because probe does not reset the channels.

Before this patch the same input would dereference a NULL canch[1], so this
is an improvement. However, the RX path now treats the new "allocated but
not yet registered" state as a detached device.

The early return in gs_usb_receive_bulk_callback() is still unchanged at the
end of the series (6f2e6f8d658b).

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130092003.1946901-2-mkl%40pengutronix.de

  parent reply	other threads:[~2026-12-01  9:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  9:15 [PATCH net-next 0/9] pull-request: can-next 2026-11-30 Marc Kleine-Budde
2026-11-30  9:15 ` [PATCH net-next 1/9] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev() Marc Kleine-Budde
2026-11-30  9:23   ` netdev-bot+sinfo
2026-11-30 20:34     ` Marc Kleine-Budde
2026-12-01  9:41   ` netdev-bot+sashiko [this message]
2026-11-30  9:15 ` [PATCH net-next 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails Marc Kleine-Budde
2026-11-30  9:15 ` [PATCH net-next 3/9] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
2026-11-30  9:15 ` [PATCH net-next 4/9] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
2026-12-01  9:20   ` sashiko-bot
2026-11-30  9:15 ` [PATCH net-next 5/9] can: gs_usb: fix hardware timestamp state for mixed channels Marc Kleine-Budde
2026-11-30  9:15 ` [PATCH net-next 6/9] can: gs_usb: add support for context analysis Marc Kleine-Budde
2026-11-30  9:15 ` [PATCH net-next 7/9] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value Marc Kleine-Budde
2026-11-30  9:15 ` [PATCH net-next 8/9] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info_ratelimited() to print re-submit info messages Marc Kleine-Budde
2026-12-01  9:41   ` netdev-bot+sashiko
2026-11-30  9:15 ` [PATCH net-next 9/9] can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces 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=179611808903.3146.10926780520247936704@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=shuangpeng.kernel@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=vadim.fedorenko@linux.dev \
    /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