summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancois Berder <[email protected]>2026-05-09 19:22:41 +0200
committerMattijs Korpershoek <[email protected]>2026-05-13 13:11:07 +0200
commitc8f68234422b8afb516fea2336b678750f10ba5b (patch)
tree789fe45ff426f893e2bf17d809e598595d4edb65
parent36d4c653580824b16574560b21d4401614d8b68e (diff)
usb: gadget: f_acm: Fix memory leak in acm_add
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 <[email protected]> Reviewed-by: Marek Vasut <[email protected]> Reviewed-by: Mattijs Korpershoek <[email protected]> Link: https://patch.msgid.link/BESP194MB2805271AD5DBE47B322F8DC3DA3A2@BESP194MB2805.EURP194.PROD.OUTLOOK.COM Signed-off-by: Mattijs Korpershoek <[email protected]>
-rw-r--r--drivers/usb/gadget/f_acm.c12
1 files 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;
}