Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Celeste Liu <uwu@coelacanthus.name>
Cc: stable@vger.kernel.org, Runcheng Lu <runcheng.lu@hpmicro.com>,
	Vincent Mailhol <mailhol@kernel.org>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: Re: [PATCH 5.15.y] can: gs_usb: increase max interface to U8_MAX
Date: Mon, 27 Oct 2025 12:36:36 +0100	[thread overview]
Message-ID: <2025102727-wing-symphony-713d@gregkh> (raw)
In-Reply-To: <20251020122529.1518396-2-uwu@coelacanthus.name>

On Mon, Oct 20, 2025 at 08:25:30PM +0800, Celeste Liu wrote:
> commit 2a27f6a8fb5722223d526843040f747e9b0e8060 upstream
> 
> This issue was found by Runcheng Lu when develop HSCanT USB to CAN FD
> converter[1]. The original developers may have only 3 interfaces
> device to test so they write 3 here and wait for future change.
> 
> During the HSCanT development, we actually used 4 interfaces, so the
> limitation of 3 is not enough now. But just increase one is not
> future-proofed. Since the channel index type in gs_host_frame is u8,
> just make canch[] become a flexible array with a u8 index, so it
> naturally constraint by U8_MAX and avoid statically allocate 256
> pointer for every gs_usb device.
> 
> [1]: https://github.com/cherry-embedded/HSCanT-hardware
> 
> Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
> Reported-by: Runcheng Lu <runcheng.lu@hpmicro.com>
> Cc: stable@vger.kernel.org
> Reviewed-by: Vincent Mailhol <mailhol@kernel.org>
> Signed-off-by: Celeste Liu <uwu@coelacanthus.name>
> Link: https://patch.msgid.link/20250930-gs-usb-max-if-v5-1-863330bf6666@coelacanthus.name
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/net/can/usb/gs_usb.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index 7dc4fb574e45..33800bb75064 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -157,10 +157,6 @@ struct gs_host_frame {
>  #define GS_MAX_TX_URBS 10
>  /* Only launch a max of GS_MAX_RX_URBS usb requests at a time. */
>  #define GS_MAX_RX_URBS 30
> -/* Maximum number of interfaces the driver supports per device.
> - * Current hardware only supports 2 interfaces. The future may vary.
> - */
> -#define GS_MAX_INTF 2
>  
>  struct gs_tx_context {
>  	struct gs_can *dev;
> @@ -191,10 +187,11 @@ struct gs_can {
>  
>  /* usb interface struct */
>  struct gs_usb {
> -	struct gs_can *canch[GS_MAX_INTF];
>  	struct usb_anchor rx_submitted;
>  	struct usb_device *udev;
>  	u8 active_channels;
> +	u8 channel_cnt;
> +	struct gs_can *canch[] __counted_by(channel_cnt);
>  };
>  
>  /* 'allocate' a tx context.
> @@ -322,7 +319,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
>  	}
>  
>  	/* device reports out of range channel id */
> -	if (hf->channel >= GS_MAX_INTF)
> +	if (hf->channel >= usbcan->channel_cnt)
>  		goto device_detach;
>  
>  	dev = usbcan->canch[hf->channel];
> @@ -410,7 +407,7 @@ 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 < GS_MAX_INTF; rc++) {
> +		for (rc = 0; rc < usbcan->channel_cnt; rc++) {
>  			if (usbcan->canch[rc])
>  				netif_device_detach(usbcan->canch[rc]->netdev);
>  		}
> @@ -993,20 +990,22 @@ static int gs_usb_probe(struct usb_interface *intf,
>  	icount = dconf->icount + 1;
>  	dev_info(&intf->dev, "Configuring for %d interfaces\n", icount);
>  
> -	if (icount > GS_MAX_INTF) {
> +	if (icount > type_max(typeof(dev->channel_cnt))) {
>  		dev_err(&intf->dev,
> -			"Driver cannot handle more that %d CAN interfaces\n",
> -			GS_MAX_INTF);
> +			"Driver cannot handle more that %u CAN interfaces\n",
> +			type_max(typeof(dev->channel_cnt)));
>  		kfree(dconf);
>  		return -EINVAL;
>  	}
>  
> -	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> +	dev = kzalloc(struct_size(dev, canch, icount), GFP_KERNEL);
>  	if (!dev) {
>  		kfree(dconf);
>  		return -ENOMEM;
>  	}
>  
> +	dev->channel_cnt = icount;
> +
>  	init_usb_anchor(&dev->rx_submitted);
>  
>  	usb_set_intfdata(intf, dev);
> @@ -1047,7 +1046,7 @@ static void gs_usb_disconnect(struct usb_interface *intf)
>  		return;
>  	}
>  
> -	for (i = 0; i < GS_MAX_INTF; i++)
> +	for (i = 0; i < dev->channel_cnt; i++)
>  		if (dev->canch[i])
>  			gs_destroy_candev(dev->canch[i]);
>  
> -- 
> 2.51.1.dirty
> 
> 

Breaks the build :(

  reply	other threads:[~2025-10-27 11:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20  8:12 FAILED: patch "[PATCH] can: gs_usb: increase max interface to U8_MAX" failed to apply to 5.15-stable tree gregkh
2025-10-20 12:25 ` [PATCH 5.15.y] can: gs_usb: increase max interface to U8_MAX Celeste Liu
2025-10-27 11:36   ` Greg KH [this message]
2025-10-27 12:49     ` Celeste Liu
2025-10-27 12:47 ` Celeste Liu

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=2025102727-wing-symphony-713d@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=runcheng.lu@hpmicro.com \
    --cc=stable@vger.kernel.org \
    --cc=uwu@coelacanthus.name \
    /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