[PATCH] can: gs_usb: gs_usb_receive_bulk_callback(): unanchor URL on usb_submit_urb() error

Marc Kleine-Budde posted 1 patch 3 weeks, 3 days ago
drivers/net/can/usb/gs_usb.c | 7 +++++++
1 file changed, 7 insertions(+)
[PATCH] can: gs_usb: gs_usb_receive_bulk_callback(): unanchor URL on usb_submit_urb() error
Posted by Marc Kleine-Budde 3 weeks, 3 days ago
In commit 7352e1d5932a ("can: gs_usb: gs_usb_receive_bulk_callback(): fix
URB memory leak"), the URB was re-anchored before usb_submit_urb() in
gs_usb_receive_bulk_callback() to prevent a leak of this URB during
cleanup.

However, this patch did not take into account that usb_submit_urb() could
fail. The URB remains anchored and
usb_kill_anchored_urbs(&parent->rx_submitted) in gs_can_close() loops
infinitely since the anchor list never becomes empty.

To fix the bug, unanchor the URB when an usb_submit_urb() error occurs,
also print an info message

Fixes: 7352e1d5932a ("can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak")
Reported-by: Jakub Kicinski <kuba@kernel.org>
Closes: https://lore.kernel.org/all/20260110223836.3890248-1-kuba@kernel.org/
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/gs_usb.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index d093babbc320..192338b481f2 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -754,6 +754,10 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
 	usb_anchor_urb(urb, &parent->rx_submitted);
 
 	rc = usb_submit_urb(urb, GFP_ATOMIC);
+	if (!rc)
+		return;
+
+	usb_unanchor_urb(urb);
 
 	/* USB failure take down all interfaces */
 	if (rc == -ENODEV) {
@@ -762,6 +766,9 @@ 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(urb->status));
 	}
 }
 

---
base-commit: 61fb66044fe862612719a3579ff2ec2294e26051
change-id: 20260116-can_usb-fix-reanchor-fa4a1e40a4f2

Best regards,
--  
Marc Kleine-Budde <mkl@pengutronix.de>
Re: [PATCH] can: gs_usb: gs_usb_receive_bulk_callback(): unanchor URL on usb_submit_urb() error
Posted by Marc Kleine-Budde 3 weeks, 2 days ago
On 16.01.2026 18:00:31, Marc Kleine-Budde wrote:
> In commit 7352e1d5932a ("can: gs_usb: gs_usb_receive_bulk_callback(): fix
> URB memory leak"), the URB was re-anchored before usb_submit_urb() in
> gs_usb_receive_bulk_callback() to prevent a leak of this URB during
> cleanup.
>
> However, this patch did not take into account that usb_submit_urb() could
> fail. The URB remains anchored and
> usb_kill_anchored_urbs(&parent->rx_submitted) in gs_can_close() loops
> infinitely since the anchor list never becomes empty.
>
> To fix the bug, unanchor the URB when an usb_submit_urb() error occurs,
> also print an info message
>
> Fixes: 7352e1d5932a ("can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak")
> Reported-by: Jakub Kicinski <kuba@kernel.org>
> Closes: https://lore.kernel.org/all/20260110223836.3890248-1-kuba@kernel.org/
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

Applied to linux-can.

Thanks,
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   |