* [U-Boot] [PATCH] usb: gadget: f_dfu.c: fix memory leak
@ 2019-06-27 13:16 Ralph Siemsen
2019-06-27 15:38 ` Ralph Siemsen
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ralph Siemsen @ 2019-06-27 13:16 UTC (permalink / raw)
To: u-boot
dfu_prepare_function() allocates N+1 descriptor header structures,
the last one being the "DFU Functional Descriptor".
dfu_unbind() handles de-allocation, but failes 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@linaro.org>
---
Notes:
The array of pointers allocated in dfu_prepare_function() is larger
than necessary. For some reason it is N+2 when N+1 would suffice.
Not a memory leak, so did not address in this commit.
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) {
free(f_dfu->function[--i]);
f_dfu->function[i] = NULL;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] usb: gadget: f_dfu.c: fix memory leak
2019-06-27 13:16 [U-Boot] [PATCH] usb: gadget: f_dfu.c: fix memory leak Ralph Siemsen
@ 2019-06-27 15:38 ` Ralph Siemsen
2019-06-28 14:42 ` [U-Boot] [RESEND PATCH v2] " Ralph Siemsen
2019-07-04 8:18 ` [U-Boot] [PATCH] " Lukasz Majewski
2 siblings, 0 replies; 4+ messages in thread
From: Ralph Siemsen @ 2019-06-27 15:38 UTC (permalink / raw)
To: u-boot
Small correction:
> Notes:
> The array of pointers allocated in dfu_prepare_function() is larger
> than necessary. For some reason it is N+2 when N+1 would suffice.
> Not a memory leak, so did not address in this commit.
Please ignore that note... the N+2 element is indeed needed, it
serves as NULL terminator for the list. Not sure how I missed that.
Ralph
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [RESEND PATCH v2] usb: gadget: f_dfu.c: fix memory leak
2019-06-27 13:16 [U-Boot] [PATCH] usb: gadget: f_dfu.c: fix memory leak Ralph Siemsen
2019-06-27 15:38 ` Ralph Siemsen
@ 2019-06-28 14:42 ` Ralph Siemsen
2019-07-04 8:18 ` [U-Boot] [PATCH] " Lukasz Majewski
2 siblings, 0 replies; 4+ messages in thread
From: Ralph Siemsen @ 2019-06-28 14:42 UTC (permalink / raw)
To: u-boot
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@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) {
free(f_dfu->function[--i]);
f_dfu->function[i] = NULL;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] usb: gadget: f_dfu.c: fix memory leak
2019-06-27 13:16 [U-Boot] [PATCH] usb: gadget: f_dfu.c: fix memory leak Ralph Siemsen
2019-06-27 15:38 ` Ralph Siemsen
2019-06-28 14:42 ` [U-Boot] [RESEND PATCH v2] " Ralph Siemsen
@ 2019-07-04 8:18 ` Lukasz Majewski
2 siblings, 0 replies; 4+ messages in thread
From: Lukasz Majewski @ 2019-07-04 8:18 UTC (permalink / raw)
To: u-boot
Hi Ralph,
> dfu_prepare_function() allocates N+1 descriptor header structures,
> the last one being the "DFU Functional Descriptor".
>
> dfu_unbind() handles de-allocation, but failes 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@linaro.org>
Thank you for the fix. I've just noticed it (as I was not on CC).
For the future patches please either use patman tool:
https://github.com/ARM-software/u-boot/tree/master/tools/patman
or use get_maitainer script, so the patch will be send directly to
responsible custodian (Maitainer).
> ---
>
> Notes:
> The array of pointers allocated in dfu_prepare_function() is
> larger than necessary. For some reason it is N+2 when N+1 would
> suffice. Not a memory leak, so did not address in this commit.
>
> 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) {
> free(f_dfu->function[--i]);
> f_dfu->function[i] = NULL;
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190704/48e49537/attachment.sig>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-04 8:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-27 13:16 [U-Boot] [PATCH] usb: gadget: f_dfu.c: fix memory leak Ralph Siemsen
2019-06-27 15:38 ` Ralph Siemsen
2019-06-28 14:42 ` [U-Boot] [RESEND PATCH v2] " Ralph Siemsen
2019-07-04 8:18 ` [U-Boot] [PATCH] " Lukasz Majewski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.