* [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
* Re: [PATCH v2] usb: gadget: f_acm: Fix memory leak in acm_add
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
2 siblings, 0 replies; 4+ messages in thread
From: Mattijs Korpershoek @ 2026-05-11 9:02 UTC (permalink / raw)
To: Francois Berder, u-boot
Cc: Lukasz Majewski, Mattijs Korpershoek, Marek Vasut, Tom Rini
Hi Francois,
Thank you for the patch.
On Sat, May 09, 2026 at 19:22, Francois Berder <fberder@outlook.fr> wrote:
> 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>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
> ---
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] usb: gadget: f_acm: Fix memory leak in acm_add
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
2 siblings, 0 replies; 4+ messages in thread
From: Marek Vasut @ 2026-05-11 11:38 UTC (permalink / raw)
To: Francois Berder, u-boot; +Cc: Lukasz Majewski, Mattijs Korpershoek, Tom Rini
On 5/9/26 7:22 PM, Francois Berder wrote:
> 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>
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Thank you
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] usb: gadget: f_acm: Fix memory leak in acm_add
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
2 siblings, 0 replies; 4+ messages in thread
From: Mattijs Korpershoek @ 2026-05-13 11:11 UTC (permalink / raw)
To: u-boot, Francois Berder; +Cc: Lukasz Majewski, Marek Vasut, Tom Rini
Hi,
On Sat, 09 May 2026 19:22:41 +0200, Francois Berder wrote:
> If udc_device_get_by_index fails, the f_acm struct was not released.
> Free it before returning the error.
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)
[1/1] usb: gadget: f_acm: Fix memory leak in acm_add
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/c8f68234422b8afb516fea2336b678750f10ba5b
--
Mattijs
^ permalink raw reply [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