* [PATCH can-next v11 1/9] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev()
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails Marc Kleine-Budde
` (7 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde, stable
In gs_usb_probe(), gs_make_candev() is called to allocate and set up the
CAN channel, as well as to call register_candev(). However, gs_usb_probe()
defers the assignment of dev->parent and parent->hf_size_rx until after
gs_make_candev() returns. This opens a race window for the user space to
bring up the CAN interface, while it's not completely setup.
To close the race window, initialize all CAN interfaces in a first loop and
then register them in a second loop: Don't call register_candev() from
gs_make_candev() but explicitly from gs_usb_probe(). Adjust
gs_destroy_candev() likewise, move unregister_candev() to
gs_usb_disconnect() and the error paths in gs_usb_probe(), to keep it
inverse to symmetric to gs_make_candev().
While moving the error message, use "%u" instead of "%d" to print the
channel number, which is an unsigned int.
Closes: https://sashiko.dev/#/bug/linux-be54de7d-0b75-408c-b3ee-dd90c9756857
Closes: https://sashiko.dev/#/bug/linux-71076d59-0843-4749-a5ab-fdd98a08582f
Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 64 +++++++++++++++++++++++++++-----------------
1 file changed, 40 insertions(+), 24 deletions(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 15f28833f2de..965151ab50a1 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -1490,18 +1490,8 @@ static struct gs_can *gs_make_candev(unsigned int channel,
can_rx_offload_add_manual(netdev, &dev->offload, GS_NAPI_WEIGHT);
SET_NETDEV_DEV(netdev, &intf->dev);
- rc = register_candev(dev->netdev);
- if (rc) {
- dev_err(&intf->dev,
- "Couldn't register candev for channel %d (%pe)\n",
- channel, ERR_PTR(rc));
- goto out_can_rx_offload_del;
- }
-
return dev;
-out_can_rx_offload_del:
- can_rx_offload_del(&dev->offload);
out_free_candev:
free_candev(dev->netdev);
return ERR_PTR(rc);
@@ -1509,7 +1499,6 @@ static struct gs_can *gs_make_candev(unsigned int channel,
static void gs_destroy_candev(struct gs_can *dev)
{
- unregister_candev(dev->netdev);
can_rx_offload_del(&dev->offload);
free_candev(dev->netdev);
}
@@ -1587,21 +1576,16 @@ static int gs_usb_probe(struct usb_interface *intf,
for (i = 0; i < icount; i++) {
unsigned int hf_size_rx = 0;
+ struct gs_can *dev;
- parent->canch[i] = gs_make_candev(i, intf, &dconf);
- if (IS_ERR_OR_NULL(parent->canch[i])) {
+ dev = gs_make_candev(i, intf, &dconf);
+ if (IS_ERR_OR_NULL(dev)) {
/* save error code to return later */
- rc = PTR_ERR(parent->canch[i]);
+ rc = PTR_ERR(dev);
- /* on failure destroy previously created candevs */
- icount = i;
- for (i = 0; i < icount; i++)
- gs_destroy_candev(parent->canch[i]);
-
- usb_kill_anchored_urbs(&parent->rx_submitted);
- kfree(parent);
- return rc;
+ goto out_gs_destroy_candev;
}
+ parent->canch[i] = dev;
parent->canch[i]->parent = parent;
/* set RX packet size based on FD and if hardware
@@ -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);
+ if (rc) {
+ const unsigned int cur = i;
+
+ dev_err(&intf->dev,
+ "Couldn't register candev for channel %u (%pe)\n",
+ i, ERR_PTR(rc));
+
+ for (i = 0; i < cur; i++)
+ unregister_candev(parent->canch[i]->netdev);
+
+ goto out_gs_destroy_candev;
+ }
+ }
+
return 0;
+
+out_gs_destroy_candev:
+ for (i = 0; i < parent->channel_cnt; i++) {
+ if (!parent->canch[i])
+ continue;
+
+ gs_destroy_candev(parent->canch[i]);
+ }
+
+ kfree(parent);
+
+ return rc;
}
static void gs_usb_disconnect(struct usb_interface *intf)
@@ -1637,8 +1651,10 @@ static void gs_usb_disconnect(struct usb_interface *intf)
}
for (i = 0; i < parent->channel_cnt; i++)
- if (parent->canch[i])
- gs_destroy_candev(parent->canch[i]);
+ unregister_candev(parent->canch[i]->netdev);
+
+ for (i = 0; i < parent->channel_cnt; i++)
+ gs_destroy_candev(parent->canch[i]);
kfree(parent);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 1/9] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev() Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-11-30 7:45 ` sashiko-bot
2026-12-01 20:53 ` netdev-bot+sashiko
2026-11-30 7:37 ` [PATCH can-next v11 3/9] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
` (6 subsequent siblings)
8 siblings, 2 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde, stable
If the device sends a CAN error frame and the SKB allocation fails, the CAN
state is not updated.
To avoid losing CAN state updates, analyze CAN error frames before
allocating the skb. Update gs_update_state() to work on a struct
gs_host_frame instead of a struct can_frame.
Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 965151ab50a1..0c65db9bbd30 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -495,23 +495,23 @@ static void gs_usb_timestamp_stop(struct gs_usb *parent)
cancel_delayed_work_sync(&parent->timestamp);
}
-static void gs_update_state(struct gs_can *dev, struct can_frame *cf)
+static void gs_update_state(struct gs_can *dev, const struct gs_host_frame *hf)
{
struct can_device_stats *can_stats = &dev->can.can_stats;
- if (cf->can_id & CAN_ERR_RESTARTED) {
+ if (hf->can_id & cpu_to_le32(CAN_ERR_RESTARTED)) {
dev->can.state = CAN_STATE_ERROR_ACTIVE;
can_stats->restarts++;
- } else if (cf->can_id & CAN_ERR_BUSOFF) {
+ } else if (hf->can_id & cpu_to_le32(CAN_ERR_BUSOFF)) {
dev->can.state = CAN_STATE_BUS_OFF;
can_stats->bus_off++;
- } else if (cf->can_id & CAN_ERR_CRTL) {
- if ((cf->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
- (cf->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
+ } else if (hf->can_id & cpu_to_le32(CAN_ERR_CRTL)) {
+ if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
+ (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
dev->can.state = CAN_STATE_ERROR_WARNING;
can_stats->error_warning++;
- } else if ((cf->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
- (cf->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
+ } else if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
+ (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
dev->can.state = CAN_STATE_ERROR_PASSIVE;
can_stats->error_passive++;
} else {
@@ -685,6 +685,10 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
memcpy(cfd->data, hf->canfd->data, data_length);
} else {
+ /* ERROR frames tell us information about the controller */
+ if (hf->can_id & cpu_to_le32(CAN_ERR_FLAG))
+ gs_update_state(dev, hf);
+
skb = alloc_can_skb(netdev, &cf);
if (!skb)
goto resubmit_urb;
@@ -693,10 +697,6 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
can_frame_set_cc_len(cf, hf->can_dlc, dev->can.ctrlmode);
memcpy(cf->data, hf->classic_can->data, data_length);
-
- /* ERROR frames tell us information about the controller */
- if (le32_to_cpu(hf->can_id) & CAN_ERR_FLAG)
- gs_update_state(dev, cf);
}
gs_usb_rx_offload(dev, skb, hf);
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
2026-11-30 7:37 ` [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails Marc Kleine-Budde
@ 2026-11-30 7:45 ` sashiko-bot
2026-11-30 8:04 ` Marc Kleine-Budde
2026-12-01 20:53 ` netdev-bot+sashiko
1 sibling, 1 reply; 18+ messages in thread
From: sashiko-bot @ 2026-11-30 7:45 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: linux-can, Oliver Hartkopp, Vincent Mailhol, Oleksij Rempel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] can: gs_usb: unvalidated data[1] read in gs_update_state() on
short frames
--
commit 30fc2459f9b225604427254c1421d65c0b0fa7b1
Author: Marc Kleine-Budde <mkl@pengutronix.de>
can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
This commit moves gs_update_state() before alloc_can_skb() in
gs_usb_receive_bulk_callback() and changes it to read directly from struct
gs_host_frame so CAN state updates are not lost if skb allocation fails.
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 965151ab50a1e..0c65db9bbd30f 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -495,23 +495,23 @@ static void gs_usb_timestamp_stop(struct gs_usb *parent)
> cancel_delayed_work_sync(&parent->timestamp);
> }
>
> -static void gs_update_state(struct gs_can *dev, struct can_frame *cf)
> +static void gs_update_state(struct gs_can *dev, const struct gs_host_frame *hf)
> {
> struct can_device_stats *can_stats = &dev->can.can_stats;
>
> - if (cf->can_id & CAN_ERR_RESTARTED) {
> + if (hf->can_id & cpu_to_le32(CAN_ERR_RESTARTED)) {
> dev->can.state = CAN_STATE_ERROR_ACTIVE;
> can_stats->restarts++;
> - } else if (cf->can_id & CAN_ERR_BUSOFF) {
> + } else if (hf->can_id & cpu_to_le32(CAN_ERR_BUSOFF)) {
> dev->can.state = CAN_STATE_BUS_OFF;
> can_stats->bus_off++;
> - } else if (cf->can_id & CAN_ERR_CRTL) {
> - if ((cf->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
> - (cf->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
> + } else if (hf->can_id & cpu_to_le32(CAN_ERR_CRTL)) {
> + if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
> + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
> dev->can.state = CAN_STATE_ERROR_WARNING;
> can_stats->error_warning++;
> - } else if ((cf->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
> - (cf->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
> + } else if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
> + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
> dev->can.state = CAN_STATE_ERROR_PASSIVE;
> can_stats->error_passive++;
> } else {
> @@ -685,6 +685,10 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
>
> memcpy(cfd->data, hf->canfd->data, data_length);
> } else {
> + /* ERROR frames tell us information about the controller */
> + if (hf->can_id & cpu_to_le32(CAN_ERR_FLAG))
> + gs_update_state(dev, hf);
[Severity: Medium]
Can gs_update_state() read uninitialized or stale memory from
hf->classic_can->data[1] when a short error frame is received?
Previously, alloc_can_skb() zeroed cf via skb_put_zero() and only
data_length validated bytes were copied into cf->data. Because
gs_usb_get_minimum_rx_length() allows classic CAN frames with
data_length < 2 (when hf->can_dlc < 2 or CAN_RTR_FLAG is set), and RX URB
buffers are allocated with kmalloc() in gs_can_open() and reused across
transfers, reading hf->classic_can->data[1] directly without checking
data_length >= 2 can inspect uninitialized or leftover payload bytes and
misupdate dev->can.state and can_stats.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4@pengutronix.de?part=2
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
2026-11-30 7:37 ` [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails Marc Kleine-Budde
2026-11-30 7:45 ` sashiko-bot
@ 2026-12-01 20:53 ` netdev-bot+sashiko
2026-12-01 20:56 ` Marc Kleine-Budde
1 sibling, 1 reply; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:53 UTC (permalink / raw)
To: mkl; +Cc: mailhol, pfink, eric, max, wg, kernel, linux-can, stable, kuba
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] In drivers/net/can/usb/gs_usb.c, this patch moves the
gs_update_state() call in gs_usb_receive_bulk_callback() ahead of…
--
can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
This patch moves the CAN error frame state check in
gs_usb_receive_bulk_callback() ahead of alloc_can_skb(), so state updates
are not lost when the skb allocation fails. gs_update_state() now takes
the raw struct gs_host_frame instead of a struct can_frame.
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 965151ab50a1e..0c65db9bbd30f 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -495,23 +495,23 @@ static void gs_usb_timestamp_stop(struct gs_usb *parent)
> cancel_delayed_work_sync(&parent->timestamp);
> }
>
> -static void gs_update_state(struct gs_can *dev, struct can_frame *cf)
> +static void gs_update_state(struct gs_can *dev, const struct gs_host_frame *hf)
> {
[ ... ]
> - } else if (cf->can_id & CAN_ERR_CRTL) {
> - if ((cf->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
> - (cf->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
> + } else if (hf->can_id & cpu_to_le32(CAN_ERR_CRTL)) {
> + if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
> + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
> dev->can.state = CAN_STATE_ERROR_WARNING;
> can_stats->error_warning++;
> - } else if ((cf->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
> - (cf->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
> + } else if ((hf->classic_can->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
> + (hf->classic_can->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
> dev->can.state = CAN_STATE_ERROR_PASSIVE;
> can_stats->error_passive++;
> } else {
[Severity: Medium]
Can gs_update_state() now read a byte of hf->classic_can->data[] that the
device never sent?
Before this patch, data[1] came from the can_frame. alloc_can_skb()
zero-fills that frame with skb_put_zero(), and then only data_length
bytes were copied in:
memcpy(cf->data, hf->classic_can->data, data_length);
For an error frame with can_dlc <= 1, or with CAN_RTR_FLAG set
(data_length == 0), cf->data[1] was therefore 0. A CAN_ERR_CRTL frame
then fell through to CAN_STATE_ERROR_ACTIVE.
Now gs_update_state() reads the byte directly from the URB transfer
buffer. Without GS_CAN_FEATURE_HW_TIMESTAMP,
gs_usb_get_minimum_rx_length() only requires the header plus data_length
bytes:
if (hf->echo_id == GS_HOST_FRAME_ECHO_ID_RX &&
!(hf->can_id & cpu_to_le32(CAN_RTR_FLAG)))
data_length = can_cc_dlc2len(hf->can_dlc);
...
else
minimum_length = sizeof(hf->header) + data_length;
So a short error frame passes validation even though data[1] was never
transferred.
gs_can_open() allocates the RX buffer without zeroing it:
buf = kmalloc(dev->parent->hf_size_rx,
GFP_KERNEL);
The buffer is then reused on every resubmit. On the first completion,
data[1] would be uninitialized heap memory. After that, it would be a
stale byte from an earlier transfer.
Could this set dev->can.state to CAN_STATE_ERROR_WARNING or
CAN_STATE_ERROR_PASSIVE, and increment error_warning or error_passive,
based on leftover buffer contents? The frame passed to userspace would
still have data[1] == 0, so the driver state and the reported frame would
disagree.
The same applies when the device sends all 8 bytes with a low DLC. The
state would come from bytes the DLC marks as invalid, while userspace
sees them zeroed.
Would it make sense to pass data_length into gs_update_state()? Another
option is something like:
u8 d1 = data_length > 1 ? hf->classic_can->data[1] : 0;
and then test d1 instead.
This code does not seem to change later in the series either.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4%40pengutronix.de
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
2026-12-01 20:53 ` netdev-bot+sashiko
@ 2026-12-01 20:56 ` Marc Kleine-Budde
0 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-12-01 20:56 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: mailhol, pfink, eric, max, wg, kernel, linux-can, stable, kuba
[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]
On 01.12.2026 20:53:23, netdev-bot+sashiko@kernel.org wrote:
> 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] In drivers/net/can/usb/gs_usb.c, this patch moves the
> gs_update_state() call in gs_usb_receive_bulk_callback() ahead of…
will fix.
pw-bot: cr
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH can-next v11 3/9] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 1/9] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev() Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 4/9] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
` (5 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde, stable
If the allocation of an SKB fails in gs_usb_receive_bulk_callback(), the
function neither updates the statistics nor checks whether an overflow flag
is set in the host frame.
Instead of directly resubmitting the URB, first update the dropped RX
statistics then check if an overflow flag is set.
Closes: https://sashiko.dev/#/bug/linux-7b3fe6a0-4628-4d0e-aec0-69f4bf8ad5d4
Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
Fixes: 26949ac935e3 ("can: gs_usb: add CAN-FD support")
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 0c65db9bbd30..23aff40e5d39 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -673,8 +673,11 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
if (hf->echo_id == GS_HOST_FRAME_ECHO_ID_RX) { /* normal rx */
if (hf->flags & GS_CAN_FLAG_FD) {
skb = alloc_canfd_skb(netdev, &cfd);
- if (!skb)
- goto resubmit_urb;
+ if (!skb) {
+ stats->rx_dropped++;
+
+ goto check_overflow;
+ }
cfd->can_id = le32_to_cpu(hf->can_id);
cfd->len = data_length;
@@ -690,8 +693,11 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
gs_update_state(dev, hf);
skb = alloc_can_skb(netdev, &cf);
- if (!skb)
- goto resubmit_urb;
+ if (!skb) {
+ stats->rx_dropped++;
+
+ goto check_overflow;
+ }
cf->can_id = le32_to_cpu(hf->can_id);
can_frame_set_cc_len(cf, hf->can_dlc, dev->can.ctrlmode);
@@ -728,6 +734,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
netif_wake_queue(netdev);
}
+check_overflow:
if (hf->flags & GS_CAN_FLAG_OVERFLOW) {
stats->rx_over_errors++;
stats->rx_errors++;
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH can-next v11 4/9] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
` (2 preceding siblings ...)
2026-11-30 7:37 ` [PATCH can-next v11 3/9] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 5/9] can: gs_usb: fix hardware timestamp state for mixed channels Marc Kleine-Budde
` (4 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde, stable
If the overflow flag is set for a host frame and the allocation of the
error SKB fails, the URB should not be resubmitted immediately.
Instead, call can_rx_offload_irq_finish(), since an SKB may have been added
to rx-offload.
Closes: https://sashiko.dev/#/bug/linux-441137e2-cd75-411f-9ff5-dc4d473c5ddb
Fixes: 24bc41b45583 ("can: gs_usb: convert to NAPI/rx-offload to avoid OoO reception")
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 23aff40e5d39..51c61eef98e7 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -741,7 +741,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
skb = alloc_can_err_skb(netdev, &cf);
if (!skb)
- goto resubmit_urb;
+ goto can_rx_offload_irq_finish;
cf->can_id |= CAN_ERR_CRTL;
cf->len = CAN_ERR_DLC;
@@ -750,6 +750,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
gs_usb_rx_offload(dev, skb, hf);
}
+can_rx_offload_irq_finish:
can_rx_offload_irq_finish(&dev->offload);
resubmit_urb:
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH can-next v11 5/9] can: gs_usb: fix hardware timestamp state for mixed channels
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
` (3 preceding siblings ...)
2026-11-30 7:37 ` [PATCH can-next v11 4/9] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis Marc Kleine-Budde
` (3 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde, Shuangpeng Bai, stable,
Vadim Fedorenko
From: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
For hardware timestamping, the driver manages the infrastructure
(cyclecounter/timecounter) for the entire USB interface, for now assuming
that all channels share a common time base, even though each channel
individually indicates support for hardware timestamping via the
GS_CAN_FEATURE_HW_TIMESTAMP flag.
Currently both the initialization and shutdown of the HW timestamping
infrastructure are tied to the flags of the first channel opened
respectively last channel closed.
If the first channel opened doesn't have the timestamping feature, but the
second does, gs_usb_timestamp_init() never runs. This leads to a NULL
pointer dereference in timecounter_cyc2time() in URB completion for the
second channel.
If the first channel opens has the timestamping feature, but the last one
closing doesn't, gs_usb_timestamp_stop() is not called, but parent is
freed. This leads to a use-after-free in the still scheduled worker.
This patch also reworks the locking around timecounter/cyclecounter. There
are competing requirements:
- the struct cyclecounter::read callback uses a sleeping USB control
transfer
- the updates during timecounter_read() must be atomic
- timecounter_cyc2time() is used from URB completion callback, which
run in BH or even IRQ context
To fix this issue, let timecounter_cyc2time() works on a snapshot of struct
cyclecounter/struct timecounter. Serialize the update of the snapshot with
a sequence counter. Update the snapshot after the timecounter_init() and in
the worker after timecounter_read().
Keep the initialization of the HW timestamping infrastructure in
gs_usb_timestamp_init(), and move initial time init and the initial
scheduling of the delayed worker into gs_usb_timestamp_start().
Initialize the HW timestamping infrastructure in gs_usb_probe() using
gs_usb_timestamp_init() if at least one channel has the
GS_CAN_FEATURE_HW_TIMESTAMP flag set.
Start and sync the timestamping infrastructure when opening the first
channel of a device that supports HW timestamps and stop it if the last
channel closes.
Reported-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Closes: https://sashiko.dev/#/bug/linux-b39360f9-6cd8-4f47-83bb-f0f78331f308
Closes: https://sashiko.dev/#/bug/linux-5f8ecd4e-344e-4ceb-9b46-886f4942a5f6
Fixes: 5886e4d5ecec ("can: gs_usb: fix time stamp counter initialization")
Cc: stable@vger.kernel.org
Cc: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Co-developed-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 87 +++++++++++++++++++++++++++++++-------------
1 file changed, 61 insertions(+), 26 deletions(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 51c61eef98e7..df24027dc0c6 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -324,19 +324,29 @@ struct gs_can {
atomic_t active_tx_urbs;
};
+enum gs_usb_parent_flags {
+ GS_USB_PARENT_FLAGS_HW_TIMESTAMP = BIT(0),
+};
+
+struct gs_usb_timer {
+ struct cyclecounter cc;
+ struct timecounter tc;
+};
+
/* usb interface struct */
struct gs_usb {
struct usb_anchor rx_submitted;
struct usb_device *udev;
/* time counter for hardware timestamps */
- struct cyclecounter cc;
- struct timecounter tc;
- spinlock_t tc_lock; /* spinlock to guard access tc->cycle_last */
+ struct gs_usb_timer tc_active;
+ struct gs_usb_timer tc_snapshot;
+ seqlock_t tc_lock; /* seqlock to guard access tc_snapshot */
struct delayed_work timestamp;
unsigned int hf_size_rx;
u8 active_channels;
+ u8 flags;
u8 channel_cnt;
unsigned int pipe_in;
@@ -423,18 +433,13 @@ static inline int gs_usb_get_timestamp(const struct gs_usb *parent,
return 0;
}
-static u64 gs_usb_timestamp_read(struct cyclecounter *cc) __must_hold(&dev->tc_lock)
+static u64 gs_usb_timestamp_read(struct cyclecounter *cc)
{
- struct gs_usb *parent = container_of(cc, struct gs_usb, cc);
+ struct gs_usb *parent = container_of(cc, struct gs_usb, tc_active.cc);
u32 timestamp = 0;
int err;
- lockdep_assert_held(&parent->tc_lock);
-
- /* drop lock for synchronous USB transfer */
- spin_unlock_bh(&parent->tc_lock);
err = gs_usb_get_timestamp(parent, ×tamp);
- spin_lock_bh(&parent->tc_lock);
if (err)
dev_err(&parent->udev->dev,
"Error %d while reading timestamp. HW timestamps may be inaccurate.",
@@ -443,15 +448,24 @@ static u64 gs_usb_timestamp_read(struct cyclecounter *cc) __must_hold(&dev->tc_l
return timestamp;
}
+static void gs_usb_timestamp_do_snapshot(struct gs_usb *parent)
+{
+ unsigned long flags;
+
+ write_seqlock_irqsave(&parent->tc_lock, flags);
+ parent->tc_snapshot = parent->tc_active;
+ parent->tc_snapshot.tc.cc = &parent->tc_snapshot.cc;
+ write_sequnlock_irqrestore(&parent->tc_lock, flags);
+}
+
static void gs_usb_timestamp_work(struct work_struct *work)
{
struct delayed_work *delayed_work = to_delayed_work(work);
struct gs_usb *parent;
parent = container_of(delayed_work, struct gs_usb, timestamp);
- spin_lock_bh(&parent->tc_lock);
- timecounter_read(&parent->tc);
- spin_unlock_bh(&parent->tc_lock);
+ timecounter_read(&parent->tc_active.tc);
+ gs_usb_timestamp_do_snapshot(parent);
schedule_delayed_work(&parent->timestamp,
GS_USB_TIMESTAMP_WORK_DELAY_SEC * HZ);
@@ -461,31 +475,39 @@ static void gs_usb_skb_set_timestamp(struct gs_can *dev,
struct sk_buff *skb, u32 timestamp)
{
struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb);
- struct gs_usb *parent = dev->parent;
+ const struct gs_usb *parent = dev->parent;
+ unsigned int seq;
u64 ns;
- spin_lock_bh(&parent->tc_lock);
- ns = timecounter_cyc2time(&parent->tc, timestamp);
- spin_unlock_bh(&parent->tc_lock);
+ do {
+ seq = read_seqbegin(&parent->tc_lock);
+ ns = timecounter_cyc2time(&parent->tc_snapshot.tc, timestamp);
+ } while (read_seqretry(&parent->tc_lock, seq));
hwtstamps->hwtstamp = ns_to_ktime(ns);
}
static void gs_usb_timestamp_init(struct gs_usb *parent)
{
- struct cyclecounter *cc = &parent->cc;
+ struct cyclecounter *cc = &parent->tc_active.cc;
cc->read = gs_usb_timestamp_read;
cc->mask = CYCLECOUNTER_MASK(32);
cc->shift = 32 - bits_per(NSEC_PER_SEC / GS_USB_TIMESTAMP_TIMER_HZ);
cc->mult = clocksource_hz2mult(GS_USB_TIMESTAMP_TIMER_HZ, cc->shift);
- spin_lock_init(&parent->tc_lock);
- spin_lock_bh(&parent->tc_lock);
- timecounter_init(&parent->tc, &parent->cc, ktime_get_real_ns());
- spin_unlock_bh(&parent->tc_lock);
+ seqlock_init(&parent->tc_lock);
INIT_DELAYED_WORK(&parent->timestamp, gs_usb_timestamp_work);
+
+ parent->flags |= GS_USB_PARENT_FLAGS_HW_TIMESTAMP;
+}
+
+static void gs_usb_timestamp_start(struct gs_usb *parent)
+{
+ timecounter_init(&parent->tc_active.tc, &parent->tc_active.cc, ktime_get_real_ns());
+ gs_usb_timestamp_do_snapshot(parent);
+
schedule_delayed_work(&parent->timestamp,
GS_USB_TIMESTAMP_WORK_DELAY_SEC * HZ);
}
@@ -988,9 +1010,12 @@ static int gs_can_open(struct net_device *netdev)
can_rx_offload_enable(&dev->offload);
+ /* rely on RTNL to serialize concurrent ifup/ifdown */
+ ASSERT_RTNL();
+
if (!parent->active_channels) {
- if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
- gs_usb_timestamp_init(parent);
+ if (parent->flags & GS_USB_PARENT_FLAGS_HW_TIMESTAMP)
+ gs_usb_timestamp_start(parent);
for (i = 0; i < GS_MAX_RX_URBS; i++) {
u8 *buf;
@@ -1105,7 +1130,7 @@ static int gs_can_open(struct net_device *netdev)
if (!parent->active_channels) {
usb_kill_anchored_urbs(&parent->rx_submitted);
- if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
+ if (parent->flags & GS_USB_PARENT_FLAGS_HW_TIMESTAMP)
gs_usb_timestamp_stop(parent);
}
@@ -1158,12 +1183,15 @@ static int gs_can_close(struct net_device *netdev)
netif_stop_queue(netdev);
+ /* rely on RTNL to serialize concurrent ifup/ifdown */
+ ASSERT_RTNL();
+
/* Stop polling */
parent->active_channels--;
if (!parent->active_channels) {
usb_kill_anchored_urbs(&parent->rx_submitted);
- if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
+ if (parent->flags & GS_USB_PARENT_FLAGS_HW_TIMESTAMP)
gs_usb_timestamp_stop(parent);
}
@@ -1522,6 +1550,7 @@ static int gs_usb_probe(struct usb_interface *intf,
.byte_order = cpu_to_le32(0x0000beef),
};
struct gs_device_config dconf;
+ bool hw_ts_supported = false;
unsigned int icount, i;
int rc;
@@ -1596,6 +1625,9 @@ static int gs_usb_probe(struct usb_interface *intf,
parent->canch[i] = dev;
parent->canch[i]->parent = parent;
+ if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
+ hw_ts_supported = true;
+
/* set RX packet size based on FD and if hardware
* timestamps are supported.
*/
@@ -1613,6 +1645,9 @@ static int gs_usb_probe(struct usb_interface *intf,
parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx);
}
+ if (hw_ts_supported)
+ gs_usb_timestamp_init(parent);
+
for (i = 0; i < icount; i++) {
struct gs_can *dev = parent->canch[i];
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
` (4 preceding siblings ...)
2026-11-30 7:37 ` [PATCH can-next v11 5/9] can: gs_usb: fix hardware timestamp state for mixed channels Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-11-30 7:44 ` sashiko-bot
2026-12-01 20:53 ` netdev-bot+sashiko
2026-11-30 7:37 ` [PATCH can-next v11 7/9] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value Marc Kleine-Budde
` (2 subsequent siblings)
8 siblings, 2 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde
Enable context analysis for the gs_usb driver.
Tag the hardware timestamp counter infrastructure in struct gs_usb as
guarded by the tc_lock. Fix the existing annotation for
gs_usb_timestamp_read(), add context analysis annotation regarding the
tc_lock to the low level timestamp reading functions.
This has been tested on Debian testing with clang-23 and clang-24.
| Debian clang version 23.1.5 (2)
| Debian clang version 24.0.0 (++20261119065354+16721c9d8e82-1~exp1)
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/Makefile | 2 ++
drivers/net/can/usb/gs_usb.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/Makefile b/drivers/net/can/usb/Makefile
index fcafb1ac262e..b2e1539f1d52 100644
--- a/drivers/net/can/usb/Makefile
+++ b/drivers/net/can/usb/Makefile
@@ -3,6 +3,8 @@
# Makefile for the Linux Controller Area Network USB drivers.
#
+CONTEXT_ANALYSIS_gs_usb.o := y
+
obj-$(CONFIG_CAN_8DEV_USB) += usb_8dev.o
obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
obj-$(CONFIG_CAN_ESD_USB) += esd_usb.o
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index df24027dc0c6..745ea33134a1 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -340,7 +340,7 @@ struct gs_usb {
/* time counter for hardware timestamps */
struct gs_usb_timer tc_active;
- struct gs_usb_timer tc_snapshot;
+ struct gs_usb_timer tc_snapshot __guarded_by(&tc_lock);
seqlock_t tc_lock; /* seqlock to guard access tc_snapshot */
struct delayed_work timestamp;
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis
2026-11-30 7:37 ` [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis Marc Kleine-Budde
@ 2026-11-30 7:44 ` sashiko-bot
2026-12-01 20:53 ` netdev-bot+sashiko
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-30 7:44 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: linux-can, Oliver Hartkopp, Vincent Mailhol, Oleksij Rempel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] can: gs_usb: commit message claims nonexistent
gs_usb_timestamp_read() changes
--
commit 202e55027a4cbf04f3893b2a2ed84b541f0f2443
Author: Marc Kleine-Budde <mkl@pengutronix.de>
can: gs_usb: add support for context analysis
This commit enables context analysis for gs_usb.o and annotates
struct gs_usb::tc_snapshot with __guarded_by(&tc_lock).
> Tag the hardware timestamp counter infrastructure in struct gs_usb as
> guarded by the tc_lock. Fix the existing annotation for
> gs_usb_timestamp_read(), add context analysis annotation regarding the
> tc_lock to the low level timestamp reading functions.
[Severity: Low]
Does the commit message still describe changes that were moved into the
preceding patch in this series?
The __must_hold(&dev->tc_lock) annotation on gs_usb_timestamp_read() was
already removed in commit "can: gs_usb: fix hardware timestamp state for
mixed channels", and this patch only enables CONTEXT_ANALYSIS_gs_usb.o
and annotates struct gs_usb::tc_snapshot without modifying
gs_usb_timestamp_read() or the low-level timestamp reading functions.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4@pengutronix.de?part=6
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis
2026-11-30 7:37 ` [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis Marc Kleine-Budde
2026-11-30 7:44 ` sashiko-bot
@ 2026-12-01 20:53 ` netdev-bot+sashiko
1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:53 UTC (permalink / raw)
To: mkl; +Cc: mailhol, pfink, eric, max, wg, kernel, linux-can, stable, kuba
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] The commit message of "can: gs_usb: add support for context
analysis" describes changes that the patch does not contain.
--
can: gs_usb: add support for context analysis
This commit enables context analysis for the gs_usb driver by setting
CONTEXT_ANALYSIS_gs_usb.o in drivers/net/can/usb/Makefile. It also marks
the tc_snapshot member of struct gs_usb as guarded by tc_lock.
> Tag the hardware timestamp counter infrastructure in struct gs_usb as
> guarded by the tc_lock. Fix the existing annotation for
> gs_usb_timestamp_read(), add context analysis annotation regarding the
> tc_lock to the low level timestamp reading functions.
[Severity: Medium]
Does this paragraph still match the diff? The patch makes only two changes.
In drivers/net/can/usb/Makefile:
CONTEXT_ANALYSIS_gs_usb.o := y
In struct gs_usb in drivers/net/can/usb/gs_usb.c:
struct gs_usb_timer tc_snapshot __guarded_by(&tc_lock);
The old __must_hold(&dev->tc_lock) on gs_usb_timestamp_read() seems to be
gone already. It was removed by the previous patch in the series, "can:
gs_usb: fix hardware timestamp state for mixed channels". That leaves no
existing annotation for this patch to fix.
This patch also adds no tc_lock annotation to gs_usb_get_timestamp() or
gs_usb_timestamp_read(). Both functions end up in a sleeping
usb_control_msg_recv(..., GFP_KERNEL), so maybe the intent was something
like __must_not_hold(&parent->tc_lock)?
A grep of gs_usb.c at this commit and at the end of the series finds no
__must_hold, __must_not_hold, __acquires, __releases or __context_unsafe.
The only annotation is the new __guarded_by on tc_snapshot.
The current code does not sleep under tc_lock. gs_usb_timestamp_work()
calls timecounter_read() before gs_usb_timestamp_do_snapshot() takes
write_seqlock_irqsave(). But without a contract on these functions,
context analysis would not catch a later change that calls them inside
the write section.
Only tc_snapshot is tagged, which covers less than "the hardware timestamp
counter infrastructure". Leaving tc_active untagged looks right, because
it is accessed outside tc_lock.
Could the commit message be updated to describe what the patch actually
does? Or were the annotation hunks for the low-level timestamp read
functions meant to be part of this patch?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4%40pengutronix.de
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH can-next v11 7/9] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
` (5 preceding siblings ...)
2026-11-30 7:37 ` [PATCH can-next v11 6/9] can: gs_usb: add support for context analysis Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 8/9] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info_ratelimited() to print re-submit info messages Marc Kleine-Budde
2026-11-30 7:37 ` [PATCH can-next v11 9/9] can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces Marc Kleine-Budde
8 siblings, 0 replies; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde, Ciprian Marian Costea
From: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
gs_make_candev() ignores the return value of can_rx_offload_add_manual().
In an upcoming series can_rx_offload will be improved and
can_rx_offload_add_manual() can fail.
Check the return value and exit via the existing free_candev() on error
path.
Signed-off-by: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
Link: https://patch.msgid.link/20260907104942.17089-4-ciprianmarian.costea@oss.nxp.com
[mkl: update patch description]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 745ea33134a1..8b297cca3d75 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -1523,7 +1523,10 @@ static struct gs_can *gs_make_candev(unsigned int channel,
dev->can.fd.data_bittiming_const = &dev->data_bt_const;
}
- can_rx_offload_add_manual(netdev, &dev->offload, GS_NAPI_WEIGHT);
+ rc = can_rx_offload_add_manual(netdev, &dev->offload, GS_NAPI_WEIGHT);
+ if (rc)
+ goto out_free_candev;
+
SET_NETDEV_DEV(netdev, &intf->dev);
return dev;
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH can-next v11 8/9] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info_ratelimited() to print re-submit info messages
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
` (6 preceding siblings ...)
2026-11-30 7:37 ` [PATCH can-next v11 7/9] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-12-01 20:53 ` netdev-bot+sashiko
2026-11-30 7:37 ` [PATCH can-next v11 9/9] can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces Marc Kleine-Budde
8 siblings, 1 reply; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde, Sashiko
If an URB is retransmitted (due to an error) before the network device can
be identified, and if this retransmission fails, netdev_info() operates
with a NULL pointer for the network device. Although this does not cause a
system crash, it does not provide any information about which device is
affected.
Replace net_ratelimit and netdev_info() with dev_info_ratelimited() to
output the affected USB device.
While there, remove the NULL pointer initialization for netdev, as it's not
longer needed.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260729102802.505168-1-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 8b297cca3d75..7cd34395f052 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -632,11 +632,11 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
{
struct gs_usb *parent = urb->context;
struct gs_can *dev;
- struct net_device *netdev = NULL;
int rc;
struct net_device_stats *stats;
struct gs_host_frame *hf = urb->transfer_buffer;
unsigned int minimum_length, data_length;
+ struct net_device *netdev;
struct gs_tx_context *txc;
struct can_frame *cf;
struct canfd_frame *cfd;
@@ -796,9 +796,10 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
if (parent->canch[rc])
netif_device_detach(parent->canch[rc]->netdev);
}
- } else if (rc != -ESHUTDOWN && net_ratelimit()) {
- netdev_info(netdev, "failed to re-submit IN URB: %pe\n",
- ERR_PTR(rc));
+ } else if (rc != -ESHUTDOWN) {
+ dev_info_ratelimited(&parent->udev->dev,
+ "failed to re-submit IN URB: %pe\n",
+ ERR_PTR(rc));
}
}
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH can-next v11 8/9] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info_ratelimited() to print re-submit info messages
2026-11-30 7:37 ` [PATCH can-next v11 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 20:53 ` netdev-bot+sashiko
0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:53 UTC (permalink / raw)
To: mkl; +Cc: mailhol, pfink, eric, max, wg, kernel, linux-can, stable, kuba
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] This patch fixes a defect that came from specific earlier
commits, but it has no Fixes: tag.
--
can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info_ratelimited() to print re-submit info messages
When the IN URB resubmit in gs_usb_receive_bulk_callback() fails, this
commit logs the message against the USB device with
dev_info_ratelimited(). Previously it used net_ratelimit() and
netdev_info(). The message now names the affected device even when the
resubmit happens before netdev is assigned, and the NULL initialization
of netdev is dropped.
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260729102802.505168-1-mkl@pengutronix.de
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260729102802.505168-1-mkl@pengutronix.de
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
[Severity: Low]
Should this patch have a Fixes: tag?
The message being changed was added by commit 79a6d1bfe114 ("can: gs_usb:
gs_usb_receive_bulk_callback(): unanchor URL on usb_submit_urb() error").
In gs_usb_receive_bulk_callback(), the early short read path jumps to
resubmit_urb before netdev is assigned:
minimum_length = sizeof(hf->header);
if (urb->actual_length < minimum_length) {
...
goto resubmit_urb;
}
If usb_submit_urb() then fails with an error other than -ENODEV or
-ESHUTDOWN, the old code passed netdev to netdev_info().
Commit 494fc029f662 ("can: gs_usb: gs_usb_receive_bulk_callback(): fix
error message") set netdev to NULL on that path. After that change the
message printed "(NULL net_device): failed to re-submit IN URB: ..."
without saying which device failed.
This patch finishes that fix and removes the NULL initialization that
494fc029f662 added. Would a tag like this help here?
Fixes: 494fc029f662 ("can: gs_usb: gs_usb_receive_bulk_callback(): fix error message")
Without it, stable trees that took 494fc029f662 have no way to find this
follow-up automatically. The other bug fixes earlier in this series
appear to carry Fixes: tags.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4%40pengutronix.de
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH can-next v11 9/9] can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces
2026-11-30 7:37 [PATCH can-next v11 0/9] gs_usb: fixes - part 1 Marc Kleine-Budde
` (7 preceding siblings ...)
2026-11-30 7:37 ` [PATCH can-next v11 8/9] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info_ratelimited() to print re-submit info messages Marc Kleine-Budde
@ 2026-11-30 7:37 ` Marc Kleine-Budde
2026-12-01 20:53 ` netdev-bot+sashiko
8 siblings, 1 reply; 18+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 7:37 UTC (permalink / raw)
To: Vincent Mailhol, Peter Fink, Eric Evenchick, Maximilian Schneider,
Wolfgang Grandegger
Cc: kernel, linux-can, Marc Kleine-Budde
If the USB device sends an invalid channel, consider this a firmware glitch
and don't detach all network interfaces of the USB device silently.
Instead, display an error message and resubmit the URB.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 7cd34395f052..e6632b5f87f5 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -665,8 +665,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
}
/* device reports out of range channel id */
- if (hf->channel >= parent->channel_cnt)
- goto device_detach;
+ if (hf->channel >= parent->channel_cnt) {
+ dev_err_ratelimited(&parent->udev->dev,
+ "channel number out of range (channel=%u, channel_cnt=%u)\n",
+ hf->channel, parent->channel_cnt);
+
+ goto resubmit_urb;
+ }
dev = parent->canch[hf->channel];
@@ -791,7 +796,6 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
/* USB failure take down all interfaces */
if (rc == -ENODEV) {
-device_detach:
for (rc = 0; rc < parent->channel_cnt; rc++) {
if (parent->canch[rc])
netif_device_detach(parent->canch[rc]->netdev);
--
2.53.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH can-next v11 9/9] can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces
2026-11-30 7:37 ` [PATCH can-next v11 9/9] can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces Marc Kleine-Budde
@ 2026-12-01 20:53 ` netdev-bot+sashiko
0 siblings, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 20:53 UTC (permalink / raw)
To: mkl; +Cc: mailhol, pfink, eric, max, wg, kernel, linux-can, stable, kuba
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] In gs_usb_receive_bulk_callback() (drivers/net/can/usb/gs_usb.c),
this patch quietly undoes a deliberate, stable-tagged hardening…
--
can: gs_usb: gs_usb_receive_bulk_callback(): emit error message on invalid channel instead of disconnecting interfaces
This commit changes how gs_usb_receive_bulk_callback() handles a frame
whose channel number is out of range. The driver used to detach every
network interface of the USB device. It now logs a rate-limited error
and resubmits the URB.
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 7cd34395f0529..e6632b5f87f58 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -665,8 +665,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
> }
>
> /* device reports out of range channel id */
> - if (hf->channel >= parent->channel_cnt)
> - goto device_detach;
> + if (hf->channel >= parent->channel_cnt) {
> + dev_err_ratelimited(&parent->udev->dev,
> + "channel number out of range (channel=%u, channel_cnt=%u)\n",
> + hf->channel, parent->channel_cnt);
> +
> + goto resubmit_urb;
> + }
[Severity: Low]
This change reverses commit 4a8737ff0687 ("can: gs_usb: fix use of
uninitialized variable, detach device on reception of invalid USB data").
That commit was tagged for stable and deliberately switched this path from
goto resubmit_urb to goto device_detach. Its commit message says:
If the channel number is bigger than the actual number of
channels assume broken or malicious USB device and shut it down.
The commit message here calls the event a "firmware glitch" and says the
old code detached the interfaces "silently". It doesn't mention
4a8737ff0687, and it doesn't say why that earlier reasoning no longer
holds.
Could the commit message reference 4a8737ff0687 and explain the change in
policy? With this patch, a device that keeps sending invalid channel
numbers is no longer shut down. Its URBs are resubmitted indefinitely,
with only rate-limited logging.
Jumping to resubmit_urb without a valid dev or netdev looks safe in this
tree, because the resubmit block only touches parent fields:
resubmit_urb:
usb_fill_bulk_urb(urb, parent->udev,
parent->pipe_in,
hf, parent->hf_size_rx,
gs_usb_receive_bulk_callback, parent);
However, 4a8737ff0687 removed this same jump because, at that time, the
resubmit path dereferenced an uninitialized dev (dev->gs_hf_size). The
safety now depends on earlier refactors, including the preceding change
that switched the resubmit failure message to dev_info_ratelimited(). It
might be worth recording that dependency in the commit message. That way,
a backport to an older tree whose resubmit_urb still uses dev won't bring
back the uninitialized pointer use.
>
> dev = parent->canch[hf->channel];
>
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-gs_usb-fixes-v11-0-3f052bb620d4%40pengutronix.de
^ permalink raw reply [flat|nested] 18+ messages in thread