Linux CAN drivers development
 help / color / mirror / Atom feed
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, shuangpeng.kernel@gmail.com,
	stable@vger.kernel.org, vadim.fedorenko@linux.dev,
	kuba@kernel.org
Subject: Re: [PATCH can-next v9 11/13] can: gs_usb: gs_usb_get_rx_data_length(): introduce new function to consolidate validation of host frame
Date: Mon, 23 Nov 2026 12:00:30 +0000	[thread overview]
Message-ID: <179543523052.3131.12523313805754975332@kernel.org> (raw)
In-Reply-To: <20261121-gs_usb-fixes-v9-11-db121d488945@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] The commit message understates what the patch does.
- [Low] In gs_usb_get_rx_data_length(), the patch declares minimum_length
  as int but prints it with %u in "short read (actual_length=%u,…

--

can: gs_usb: gs_usb_get_rx_data_length(): introduce new function to consolidate validation of host frame

This commit adds gs_usb_get_rx_data_length(), which consolidates the
validation of the struct gs_host_frame received in the bulk IN URB. It
returns the data length on success or a negative errno on error.
gs_usb_receive_bulk_callback() is converted to use it.

> Add a new function: gs_usb_get_rx_data_length() to consolidate the
> validation of the struct gs_host_frame from the received URB.

[Severity: Low]
Is this description complete? The patch seems to do more than move the
existing checks into one function.

It also adds a second helper, gs_usb_host_frame_header_valid().

An out of range TX echo_id (GS_MAX_TX_URBS <= echo_id <
GS_HOST_FRAME_ECHO_ID_RX) now increments netdev->stats.rx_errors. The old
check in the else branch of gs_usb_receive_bulk_callback() did not update
any counter.

The error print is now behind net_ratelimit(). Its text changes from
"Unexpected out of range echo id %u" to "out of range Echo ID
(echo_id=0x%08x, max_echo_id=0x%08x)".

The echo_id check now runs before the short read check. Before the patch,
a frame that was both short and had a bad echo_id bumped rx_errors and
rx_length_errors and logged "short read". Now it bumps only rx_errors and
logs the echo ID message.

Whether a frame is accepted or dropped does not change.

Could the commit message mention these behavior changes, so the patch is
not read as a pure code move?

> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index aca4f4fdc796a..e4e177aee48b0 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c

[ ... ]

> +static int
>  gs_usb_get_minimum_rx_length(const struct gs_can *dev, const struct gs_host_frame *hf,
> -			     unsigned int *data_length_p)
> +			     int *data_length_p)
>  {
>  	unsigned int minimum_length, data_length = 0;
>  
> @@ -651,6 +673,33 @@ gs_usb_get_minimum_rx_length(const struct gs_can *dev, const struct gs_host_fram
>  	return minimum_length;
>  }
>  
> +static int gs_usb_get_rx_data_length(const struct gs_can *dev,
> +				     const struct gs_host_frame *hf,
> +				     const u32 actual_length)
> +{
> +	struct net_device *netdev = dev->netdev;
> +	struct net_device_stats *stats = &netdev->stats;
> +	int minimum_length, data_length;
> +
> +	if (!gs_usb_host_frame_header_valid(dev, &hf->header))
> +		return -EINVAL;
> +
> +	minimum_length = gs_usb_get_minimum_rx_length(dev, hf, &data_length);
> +	if (actual_length < minimum_length) {
> +		stats->rx_errors++;
> +		stats->rx_length_errors++;
> +
> +		if (net_ratelimit())
> +			netdev_err(netdev,
> +				   "short read (actual_length=%u, minimum_length=%u)\n",
> +				   actual_length, minimum_length);

[Severity: Low]
minimum_length is now declared as int here, but it is still printed with
%u. The check actual_length < minimum_length also compares a u32 with an
int. The removed code in gs_usb_receive_bulk_callback() declared it as
unsigned int.

gs_usb_get_minimum_rx_length() now returns int, but its local
minimum_length is still unsigned int. The other "short read" print, in
gs_usb_get_gs_can(), uses a u32 with the same %u:

gs_usb_get_gs_can() {
	const u32 minimum_length = sizeof(*header);
	...
}

Today the values are small positive sizes, so the print and the
comparison both give correct results. If gs_usb_get_minimum_rx_length()
ever returned a negative errno, the value would print as a huge number.
The unsigned promotion in the comparison would then reject every frame.

This mismatch is still present at the end of the series. Should
minimum_length and the return type of gs_usb_get_minimum_rx_length()
stay unsigned?

> +
> +		return -EINVAL;
> +	}
> +
> +	return data_length;
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-gs_usb-fixes-v9-0-db121d488945%40pengutronix.de

  reply	other threads:[~2026-11-23 12:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 22:35 [PATCH can-next v9 00/13] gs_usb: fixes Marc Kleine-Budde
2026-11-21 22:35 ` [PATCH can-next v9 01/13] can: gs_usb: gs_usb_probe(): init netdev completely before register_candev() Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 02/13] can: gs_usb: gs_usb_receive_bulk_callback(): check for overflow flag if SKB allocation fails Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 03/13] can: gs_usb: gs_usb_receive_bulk_callback(): add missing call to can_rx_offload_irq_finish Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 04/13] can: gs_usb: use spin_lock_irqsave() instead of spin_lock_bh() to protect struct gs_usb::tc Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 05/13] can: gs_usb: fix hardware timestamp state for mixed channels Marc Kleine-Budde
2026-11-21 22:43   ` sashiko-bot
2026-11-23 12:00   ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 06/13] can: gs_usb: add support for context analysis Marc Kleine-Budde
2026-11-21 22:42   ` sashiko-bot
2026-11-23 12:00   ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 07/13] can: gs_usb: gs_make_candev(): check can_rx_offload_add_manual() return value Marc Kleine-Budde
2026-11-21 22:36 ` [PATCH can-next v9 08/13] can: gs_usb: gs_usb_receive_bulk_callback(): use dev_info() to print re-submit info messages Marc Kleine-Budde
2026-11-21 22:42   ` sashiko-bot
2026-11-23 12:00   ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 09/13] can: gs_usb: gs_usb_get_gs_can(): introduce new function to consolidate validation of struct gs_can Marc Kleine-Budde
2026-11-23 12:00   ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 10/13] can: gs_usb: gs_usb_get_gs_can(): report channel number out of range error Marc Kleine-Budde
2026-11-23 12:00   ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 11/13] can: gs_usb: gs_usb_get_rx_data_length(): introduce new function to consolidate validation of host frame Marc Kleine-Budde
2026-11-23 12:00   ` netdev-bot+sashiko [this message]
2026-11-21 22:36 ` [PATCH can-next v9 12/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop invalid CAN error frames Marc Kleine-Budde
2026-11-21 22:53   ` sashiko-bot
2026-11-21 23:02     ` Marc Kleine-Budde
2026-11-23  7:41     ` Marc Kleine-Budde
2026-11-23 12:00   ` netdev-bot+sashiko
2026-11-21 22:36 ` [PATCH can-next v9 13/13] can: gs_usb: gs_usb_host_frame_header_valid(): drop CAN frames with invalid DLC Marc Kleine-Budde
2026-11-23 12:00   ` netdev-bot+sashiko

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=179543523052.3131.12523313805754975332@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=shuangpeng.kernel@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=vadim.fedorenko@linux.dev \
    --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