Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: cdnsp: Fix potential ring leak on stream allocation failure
@ 2026-12-06  1:42 Tian Xuechen
  2026-12-06  1:53 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Tian Xuechen @ 2026-12-06  1:42 UTC (permalink / raw)
  To: pawell; +Cc: gregkh, peter.chen, linux-usb, linux-kernel

From: Tian Xuechen <202300460064@mail.sdu.edu.cn>

Endpoint initialization allocates the ring before its streams. If stream
allocation fails, the endpoint remains disabled and its ring is not freed.

Free the ring and clear the endpoint context before returning the error.

This issue was found by our static analysis tool under development.

Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
 drivers/usb/cdns3/cdnsp-mem.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/cdns3/cdnsp-mem.c b/drivers/usb/cdns3/cdnsp-mem.c
index 419309c..f2a18d2 100644
--- a/drivers/usb/cdns3/cdnsp-mem.c
+++ b/drivers/usb/cdns3/cdnsp-mem.c
@@ -1006,8 +1006,12 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,
 	if (usb_endpoint_xfer_bulk(pep->endpoint.desc) &&
 	    pdev->gadget.speed > USB_SPEED_HIGH) {
 		ret = cdnsp_alloc_streams(pdev, pep);
-		if (ret < 0)
+		if (ret < 0) {
+			cdnsp_ring_free(pdev, pep->ring);
+			pep->ring = NULL;
+			cdnsp_endpoint_zero(pdev, pep);
 			return ret;
+		}
 	}
 
 	return 0;

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
-- 
2.53.0


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

* Re: [PATCH] usb: cdnsp: Fix potential ring leak on stream allocation failure
  2026-12-06  1:42 [PATCH] usb: cdnsp: Fix potential ring leak on stream allocation failure Tian Xuechen
@ 2026-12-06  1:53 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-06  1:53 UTC (permalink / raw)
  To: Tian Xuechen; +Cc: linux-usb

> From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
> 
> Endpoint initialization allocates the ring before its streams. If stream
> allocation fails, the endpoint remains disabled and its ring is not freed.
> 
> Free the ring and clear the endpoint context before returning the error.
> 
> This issue was found by our static analysis tool under development.
> 
> Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
> Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206014241.3413283-1-202300460064@mail.sdu.edu.cn?part=1

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

end of thread, other threads:[~2026-12-06  1:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  1:42 [PATCH] usb: cdnsp: Fix potential ring leak on stream allocation failure Tian Xuechen
2026-12-06  1:53 ` sashiko-bot

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