[U-Boot] [RESEND PATCH v2] usb: gadget: f_dfu.c: fix memory leak

Ralph Siemsen ralph.siemsen at linaro.org
Fri Jun 28 14:42:02 UTC 2019

dfu_prepare_function() allocates N+1 descriptor header structures,
the last one being the "DFU Functional Descriptor".

dfu_unbind() handles de-allocation, but fails to free the final
one (eg. "DFU Functional Descriptor"), leading to memory leak.

Fixed by incrementing counter, as in dfu_prepare_function().

Signed-off-by: Ralph Siemsen <ralph.siemsen at linaro.org>

Changes in v2:
Remove incorrect note.
Fix spelling error in commit message.

 drivers/usb/gadget/f_dfu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c
index 30ece524a8..e27f146605 100644
--- a/drivers/usb/gadget/f_dfu.c
+++ b/drivers/usb/gadget/f_dfu.c
@@ -748,6 +748,7 @@ static void dfu_unbind(struct usb_configuration *c, struct usb_function *f)
 	if (f_dfu->function) {
 		i = alt_num;
+		i++; /* free DFU Functional Descriptor */
 		while (i) {
 			f_dfu->function[i] = NULL;

More information about the U-Boot mailing list