U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: gadget: f_acm: Fix memory leak in acm_add
@ 2026-05-09 17:22 Francois Berder
  2026-05-11  9:02 ` Mattijs Korpershoek
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Francois Berder @ 2026-05-09 17:22 UTC (permalink / raw)
  To: u-boot; +Cc: Lukasz Majewski, Mattijs Korpershoek, Marek Vasut, Tom Rini

If udc_device_get_by_index fails, the f_acm struct was not released.
Free it before returning the error.

Signed-off-by: Francois Berder <fberder@outlook.fr>
---
 drivers/usb/gadget/f_acm.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 8f7256069f5..b6c11d97a62 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -548,13 +548,11 @@ static int acm_add(struct usb_configuration *c)
 
 	status = udc_device_get_by_index(0, &f_acm->udc);
 	if (status)
-		return status;
+		goto err;
 
 	status = usb_add_function(c, &f_acm->usb_function);
-	if (status) {
-		free(f_acm);
-		return status;
-	}
+	if (status)
+		goto err;
 
 	buf_init(&f_acm->rx_buf, 2048);
 	buf_init(&f_acm->tx_buf, 2048);
@@ -562,6 +560,10 @@ static int acm_add(struct usb_configuration *c)
 	if (!default_acm_function)
 		default_acm_function = f_acm;
 
+	return 0;
+
+err:
+	free(f_acm);
 	return status;
 }
 
-- 
2.43.0

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09 17:22 [PATCH v2] usb: gadget: f_acm: Fix memory leak in acm_add Francois Berder
2026-05-11  9:02 ` Mattijs Korpershoek
2026-05-11 11:38 ` Marek Vasut
2026-05-13 11:11 ` Mattijs Korpershoek

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