Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_tcm: Free data buffer on read queue failure
@ 2026-12-04  6:19 Wanhui Fu
  2026-12-04  6:36 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Wanhui Fu @ 2026-12-04  6:19 UTC (permalink / raw)
  To: nkapron, gregkh, jiashengjiangcool, shuangpeng.kernel,
	christophe.jaillet, yun.zhou, zzzccc427, nab, balbi, bigeasy
  Cc: linux-usb, Wanhui Fu

uasp_prepare_r_request() may allocate a data buffer. If
usb_ep_queue() fails, uasp_status_data_cmpl() returns
without doing cleanup, resulting in a memory leak.

Jump to the existing cleanup path to fix this.

Found by a self-developed static analysis tool and
compile-test passed.

Fixes: c52661d60f63 ("usb-gadget: Initial merge of target module for UASP + BOT")
Signed-off-by: Wanhui Fu <fuwh1120@163.com>
---
 drivers/usb/gadget/function/f_tcm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
index 9e6d4f39900a..7f520137d966 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -682,8 +682,10 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req)
 		if (ret)
 			goto cleanup;
 		ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC);
-		if (ret)
+		if (ret) {
 			pr_err("%s(%d) => %d\n", __func__, __LINE__, ret);
+			goto cleanup;
+		}
 		break;
 
 	case UASP_RECEIVE_DATA:
-- 
2.25.1


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

* Re: [PATCH] usb: gadget: f_tcm: Free data buffer on read queue failure
  2026-12-04  6:19 [PATCH] usb: gadget: f_tcm: Free data buffer on read queue failure Wanhui Fu
@ 2026-12-04  6:36 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04  6:36 UTC (permalink / raw)
  To: Wanhui Fu; +Cc: linux-usb

> uasp_prepare_r_request() may allocate a data buffer. If
> usb_ep_queue() fails, uasp_status_data_cmpl() returns
> without doing cleanup, resulting in a memory leak.
> 
> Jump to the existing cleanup path to fix this.
> 
> Found by a self-developed static analysis tool and
> compile-test passed.
> 
> Fixes: c52661d60f63 ("usb-gadget: Initial merge of target module for UASP + BOT")
> Signed-off-by: Wanhui Fu <fuwh1120@163.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204061952.1513011-1-fuwh1120@163.com?part=1

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

end of thread, other threads:[~2026-12-04  6:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  6:19 [PATCH] usb: gadget: f_tcm: Free data buffer on read queue failure Wanhui Fu
2026-12-04  6:36 ` sashiko-bot

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