On 5/8/26 9:46 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 <[email protected]>
---
  drivers/usb/gadget/f_acm.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 8f7256069f5..0d8a3183330 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -547,8 +547,10 @@ static int acm_add(struct usb_configuration *c)
        f_acm->usb_function.setup = acm_setup;
status = udc_device_get_by_index(0, &f_acm->udc);
-       if (status)
+       if (status) {
+               free(f_acm);
                return status;

Please add a fail path:

goto err;

+       }
status = usb_add_function(c, &f_acm->usb_function);
        if (status) {

goto err;

...

err:
  free(...);
  return status;
}

Reply via email to