From: Jakub Kicinski <kuba@kernel.org>
To: mkl@pengutronix.de
Cc: Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, mailhol@kernel.org,
ondrej.ille@gmail.com, linux-can@vger.kernel.org,
davem@davemloft.net, kernel@pengutronix.de,
swilczek.lx@gmail.com, pisa@fel.cvut.cz,
syzbot+e8cb6691a7cf68256cb8@syzkaller.appspotmail.com,
stable@vger.kernel.org
Subject: Re: [net,2/3] can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak
Date: Sat, 10 Jan 2026 14:38:36 -0800 [thread overview]
Message-ID: <20260110223836.3890248-1-kuba@kernel.org> (raw)
In-Reply-To: <20260109135311.576033-3-mkl@pengutronix.de>
This is an AI-generated review of your patch.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak
This patch fixes a memory leak by re-anchoring the URB in
gs_usb_receive_bulk_callback() before resubmission. The USB framework
unanchors URBs before calling the completion callback, so the URB needs to
be re-anchored to be tracked by usb_kill_anchored_urbs() in gs_can_close().
Link: https://patch.msgid.link/20260105-gs_usb-fix-memory-leak-v2-1-cc6ed6438034@pengutronix.de
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index a0233e550a5a..d093babbc320 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -751,6 +751,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
> hf, parent->hf_size_rx,
> gs_usb_receive_bulk_callback, parent);
>
> + usb_anchor_urb(urb, &parent->rx_submitted);
> +
> rc = usb_submit_urb(urb, GFP_ATOMIC);
If usb_submit_urb() fails here, the URB remains anchored but is never
submitted. When gs_can_close() later calls usb_kill_anchored_urbs(), it
iterates over anchored URBs and calls usb_kill_urb() on each one. For URBs
that were never successfully submitted, use_count is 0, so usb_kill_urb()
returns without unanchoring them. This causes usb_kill_anchored_urbs() to
loop infinitely on the same URB since the anchor list never becomes empty.
Other CAN USB drivers handle this by calling usb_unanchor_urb() when
submission fails. For example, peak_usb_read_bulk_callback() does:
usb_anchor_urb(urb, &dev->rx_submitted);
err = usb_submit_urb(urb, GFP_ATOMIC);
if (!err)
return;
usb_unanchor_urb(urb);
Should similar error handling be added here to avoid potential hangs when
closing the device after a URB submission failure?
>
> /* USB failure take down all interfaces */
> if (rc == -ENODEV) {
[ ... ]
next prev parent reply other threads:[~2026-01-10 22:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 13:46 [PATCH net 0/3] pull-request: can 2026-01-09 Marc Kleine-Budde
2026-01-09 13:46 ` [PATCH net 1/3] can: etas_es58x: allow partial RX URB allocation to succeed Marc Kleine-Budde
2026-01-12 20:56 ` patchwork-bot+netdevbpf
2026-01-09 13:46 ` [PATCH net 2/3] can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak Marc Kleine-Budde
2026-01-10 22:38 ` Jakub Kicinski [this message]
2026-01-16 17:02 ` [net,2/3] " Marc Kleine-Budde
2026-01-09 13:46 ` [PATCH net 3/3] can: ctucanfd: fix SSP_SRC in cases when bit-rate is higher than 1 MBit Marc Kleine-Budde
2026-01-10 22:38 ` [PATCH net 0/3] pull-request: can 2026-01-09 Jakub Kicinski
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=20260110223836.3890248-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=ondrej.ille@gmail.com \
--cc=pisa@fel.cvut.cz \
--cc=stable@vger.kernel.org \
--cc=swilczek.lx@gmail.com \
--cc=syzbot+e8cb6691a7cf68256cb8@syzkaller.appspotmail.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