public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: core: Fix possible memleak in usb_add_gadget
@ 2021-09-04 15:34 Florian Faber
  2021-09-04 16:12 ` Alan Stern
  2021-09-05 14:56 ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Florian Faber @ 2021-09-04 15:34 UTC (permalink / raw)
  To: gregkh, linux-usb

The memory for the udc structure allocated via kzalloc in line 1295 is 
not freed in the error handling code, leading to a memory leak in case 
of an error.

Singed-off-by: Florian Faber <faber@faberman.de>

---
  drivers/usb/gadget/udc/core.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 14fdf918ecfe..a1270a44855a 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1346,6 +1346,8 @@ int usb_add_gadget(struct usb_gadget *gadget)

   err_put_udc:
  	put_device(&udc->dev);
+	kfree(udc);
+	gadget->udc = NULL;

   error:
  	return ret;
-- 
2.33.0

Flo
-- 
Machines can do the work, so people have time to think.

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

end of thread, other threads:[~2021-09-05 20:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-04 15:34 [PATCH] usb: core: Fix possible memleak in usb_add_gadget Florian Faber
2021-09-04 16:12 ` Alan Stern
2021-09-05 14:56 ` Greg KH
2021-09-05 15:16   ` Florian Faber
2021-09-05 16:27     ` Greg KH
2021-09-05 19:58       ` Florian Faber

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