stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 01/10] can: gs_usb: increase max interface to U8_MAX
       [not found] <20251014122140.990472-1-mkl@pengutronix.de>
@ 2025-10-14 12:17 ` Marc Kleine-Budde
  2025-10-16  1:20   ` patchwork-bot+netdevbpf
  2025-10-14 12:17 ` [PATCH net 02/10] can: gs_usb: gs_make_candev(): populate net_device->dev_port Marc Kleine-Budde
  1 sibling, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2025-10-14 12:17 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Celeste Liu, Runcheng Lu, stable,
	Vincent Mailhol, Marc Kleine-Budde

From: Celeste Liu <uwu@coelacanthus.name>

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 | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index c9482d6e947b..9fb4cbbd6d6d 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -289,11 +289,6 @@ struct gs_host_frame {
 #define GS_MAX_RX_URBS 30
 #define GS_NAPI_WEIGHT 32
 
-/* Maximum number of interfaces the driver supports per device.
- * Current hardware only supports 3 interfaces. The future may vary.
- */
-#define GS_MAX_INTF 3
-
 struct gs_tx_context {
 	struct gs_can *dev;
 	unsigned int echo_id;
@@ -324,7 +319,6 @@ 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;
 
@@ -336,9 +330,11 @@ struct gs_usb {
 
 	unsigned int hf_size_rx;
 	u8 active_channels;
+	u8 channel_cnt;
 
 	unsigned int pipe_in;
 	unsigned int pipe_out;
+	struct gs_can *canch[] __counted_by(channel_cnt);
 };
 
 /* 'allocate' a tx context.
@@ -599,7 +595,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 >= parent->channel_cnt)
 		goto device_detach;
 
 	dev = parent->canch[hf->channel];
@@ -699,7 +695,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 < parent->channel_cnt; rc++) {
 			if (parent->canch[rc])
 				netif_device_detach(parent->canch[rc]->netdev);
 		}
@@ -1460,17 +1456,19 @@ static int gs_usb_probe(struct usb_interface *intf,
 	icount = dconf.icount + 1;
 	dev_info(&intf->dev, "Configuring for %u interfaces\n", icount);
 
-	if (icount > GS_MAX_INTF) {
+	if (icount > type_max(parent->channel_cnt)) {
 		dev_err(&intf->dev,
 			"Driver cannot handle more that %u CAN interfaces\n",
-			GS_MAX_INTF);
+			type_max(parent->channel_cnt));
 		return -EINVAL;
 	}
 
-	parent = kzalloc(sizeof(*parent), GFP_KERNEL);
+	parent = kzalloc(struct_size(parent, canch, icount), GFP_KERNEL);
 	if (!parent)
 		return -ENOMEM;
 
+	parent->channel_cnt = icount;
+
 	init_usb_anchor(&parent->rx_submitted);
 
 	usb_set_intfdata(intf, parent);
@@ -1531,7 +1529,7 @@ static void gs_usb_disconnect(struct usb_interface *intf)
 		return;
 	}
 
-	for (i = 0; i < GS_MAX_INTF; i++)
+	for (i = 0; i < parent->channel_cnt; i++)
 		if (parent->canch[i])
 			gs_destroy_candev(parent->canch[i]);
 

base-commit: 2c95a756e0cfc19af6d0b32b0c6cf3bada334998
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH net 02/10] can: gs_usb: gs_make_candev(): populate net_device->dev_port
       [not found] <20251014122140.990472-1-mkl@pengutronix.de>
  2025-10-14 12:17 ` [PATCH net 01/10] can: gs_usb: increase max interface to U8_MAX Marc Kleine-Budde
@ 2025-10-14 12:17 ` Marc Kleine-Budde
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2025-10-14 12:17 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Celeste Liu, stable,
	Marc Kleine-Budde

From: Celeste Liu <uwu@coelacanthus.name>

The gs_usb driver supports USB devices with more than 1 CAN channel.
In old kernel before 3.15, it uses net_device->dev_id to distinguish
different channel in userspace, which was done in commit
acff76fa45b4 ("can: gs_usb: gs_make_candev(): set netdev->dev_id").
But since 3.15, the correct way is populating net_device->dev_port.
And according to documentation, if network device support multiple
interface, lack of net_device->dev_port SHALL be treated as a bug.

Fixes: acff76fa45b4 ("can: gs_usb: gs_make_candev(): set netdev->dev_id")
Cc: stable@vger.kernel.org
Signed-off-by: Celeste Liu <uwu@coelacanthus.name>
Link: https://patch.msgid.link/20250930-gs-usb-populate-net_device-dev_port-v1-1-68a065de6937@coelacanthus.name
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/gs_usb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 9fb4cbbd6d6d..69b8d6da651b 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -1245,6 +1245,7 @@ static struct gs_can *gs_make_candev(unsigned int channel,
 
 	netdev->flags |= IFF_ECHO; /* we support full roundtrip echo */
 	netdev->dev_id = channel;
+	netdev->dev_port = channel;
 
 	/* dev setup */
 	strcpy(dev->bt_const.name, KBUILD_MODNAME);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net 01/10] can: gs_usb: increase max interface to U8_MAX
  2025-10-14 12:17 ` [PATCH net 01/10] can: gs_usb: increase max interface to U8_MAX Marc Kleine-Budde
@ 2025-10-16  1:20   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-10-16  1:20 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, uwu, runcheng.lu, stable,
	mailhol

Hello:

This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Tue, 14 Oct 2025 14:17:48 +0200 you wrote:
> From: Celeste Liu <uwu@coelacanthus.name>
> 
> 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.
> 
> [...]

Here is the summary with links:
  - [net,01/10] can: gs_usb: increase max interface to U8_MAX
    https://git.kernel.org/netdev/net/c/2a27f6a8fb57
  - [net,02/10] can: gs_usb: gs_make_candev(): populate net_device->dev_port
    https://git.kernel.org/netdev/net/c/a12f0bc764da
  - [net,03/10] can: m_can: m_can_plat_remove(): add missing pm_runtime_disable()
    https://git.kernel.org/netdev/net/c/ba569fb07a7e
  - [net,04/10] can: m_can: m_can_handle_state_errors(): fix CAN state transition to Error Active
    https://git.kernel.org/netdev/net/c/3d9db29b45f9
  - [net,05/10] can: m_can: m_can_chip_config(): bring up interface in correct state
    https://git.kernel.org/netdev/net/c/4942c42fe184
  - [net,06/10] can: m_can: fix CAN state in system PM
    https://git.kernel.org/netdev/net/c/a9e30a22d6f2
  - [net,07/10] can: m_can: replace Dong Aisheng's old email address
    https://git.kernel.org/netdev/net/c/49836ff2f37d
  - [net,08/10] can: remove false statement about 1:1 mapping between DLC and length
    https://git.kernel.org/netdev/net/c/c282993ccd97
  - [net,09/10] can: add Transmitter Delay Compensation (TDC) documentation
    https://git.kernel.org/netdev/net/c/b5746b3e8ea4
  - [net,10/10] can: j1939: add missing calls in NETDEV_UNREGISTER notification handler
    https://git.kernel.org/netdev/net/c/93a27b5891b8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-16  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20251014122140.990472-1-mkl@pengutronix.de>
2025-10-14 12:17 ` [PATCH net 01/10] can: gs_usb: increase max interface to U8_MAX Marc Kleine-Budde
2025-10-16  1:20   ` patchwork-bot+netdevbpf
2025-10-14 12:17 ` [PATCH net 02/10] can: gs_usb: gs_make_candev(): populate net_device->dev_port Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).