Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: usbtest: free the urb when unlink1() fails early
@ 2026-11-04  2:15 Wentao Liang
  2026-11-04  7:12 ` Krzysztof Kozlowski
  2026-11-05 15:47 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-04  2:15 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb

unlink1() allocates the urb and its transfer buffer with
simple_alloc_urb() and only frees them with simple_free_urb() after the
completion has been waited for.  Two error returns skip that cleanup and
leak both the urb and its coherent buffer, which also pins the device.

usb_submit_urb() never frees the urb it was given, so the failure return
has to free it.  The unexpected usb_unlink_urb() error return still
leaves the urb submitted, so kill it first to be sure the completion
callback has run before the urb and its buffer go away.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/usb/misc/usbtest.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 8759df49be28..fb273516ee39 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -1459,6 +1459,7 @@ static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
 	retval = usb_submit_urb(urb, GFP_KERNEL);
 	if (retval != 0) {
 		dev_err(&dev->intf->dev, "submit fail %d\n", retval);
+		simple_free_urb(urb);
 		return retval;
 	}
 
@@ -1491,6 +1492,8 @@ static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
 			default:
 				dev_err(&dev->intf->dev,
 					"unlink fail %d\n", retval);
+				usb_kill_urb(urb);
+				simple_free_urb(urb);
 				return retval;
 			}
 
-- 
2.34.1


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

end of thread, other threads:[~2026-11-05 15:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  2:15 [PATCH] usb: usbtest: free the urb when unlink1() fails early Wentao Liang
2026-11-04  7:12 ` Krzysztof Kozlowski
2026-11-05 15:47 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox