From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: mailhol@kernel.org, pfink@christ-es.de, eric@evenchick.com,
max@schneidersoft.net, wg@grandegger.com, kernel@pengutronix.de,
linux-can@vger.kernel.org, stable@vger.kernel.org,
kuba@kernel.org
Subject: Re: [PATCH can-next v11 2/9] can: gs_usb: gs_usb_receive_bulk_callback(): update state even if SKB allocations fails
Date: Tue, 01 Dec 2026 20:53:23 +0000 [thread overview]
Message-ID: <179615840300.3142.4259286558647803230@kernel.org> (raw)
In-Reply-To: <20261130-gs_usb-fixes-v11-2-3f052bb620d4@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] 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
next prev parent reply other threads:[~2026-12-01 20:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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-12-01 20:53 ` netdev-bot+sashiko [this message]
2026-12-01 20:56 ` Marc Kleine-Budde
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 ` [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 ` [PATCH can-next v11 5/9] can: gs_usb: fix hardware timestamp state for mixed channels 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=179615840300.3142.4259286558647803230@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=eric@evenchick.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=max@schneidersoft.net \
--cc=mkl@pengutronix.de \
--cc=pfink@christ-es.de \
--cc=stable@vger.kernel.org \
--cc=wg@grandegger.com \
/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