public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH v2] usb: dwc3: core: fix memory leaks in event buffer cleanup
@ 2026-04-16  5:55 Gurumoorthy Santhakumar
  2026-04-16  9:06 ` Marek Vasut
  2026-04-17  8:14 ` Mattijs Korpershoek
  0 siblings, 2 replies; 3+ messages in thread
From: Gurumoorthy Santhakumar @ 2026-04-16  5:55 UTC (permalink / raw)
  To: marex, trini, mkorpershoek, macromorgan, casey.connolly,
	quic_varada, felipe.balbi, gurumoorthy.santhakumar, u-boot

In dwc3_free_one_event_buffer(), only the DMA buffer (evt->buf) was
being freed via dma_free_coherent(), but the evt structure itself was
never explicitly freed, causing a memory leak.

In dwc3_free_event_buffers(), the ev_buffs pointer array allocated
with memalign() was never freed after iterating and releasing all
individual event buffers, causing another memory leak.

Fix both leaks by freeing the evt struct in
dwc3_free_one_event_buffer() and freeing dwc->ev_buffs in
dwc3_free_event_buffers() after all entries have been released.

Signed-off-by: Gurumoorthy Santhakumar <gurumoorthy.santhakumar@oss.qualcomm.com>
---
Changes in V2:
- Removed redundant NULL check before free
- Removed NULL assignment to the pointer after free
- Link to V1:
https://lore.kernel.org/u-boot/20260414055013.2978223-1-gurumoorthy.santhakumar@oss.qualcomm.com/
---
---
 drivers/usb/dwc3/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 6f22b9232ba..65c4d1a4e6f 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -206,6 +206,7 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
 		struct dwc3_event_buffer *evt)
 {
 	dma_free_coherent(evt->buf);
+	free(evt);
 }
 
 /**
@@ -252,6 +253,8 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc)
 		if (evt)
 			dwc3_free_one_event_buffer(dwc, evt);
 	}
+
+	free(dwc->ev_buffs);
 }
 
 /**
-- 
2.34.1


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

* Re: [PATCH v2] usb: dwc3: core: fix memory leaks in event buffer cleanup
  2026-04-16  5:55 [PATCH v2] usb: dwc3: core: fix memory leaks in event buffer cleanup Gurumoorthy Santhakumar
@ 2026-04-16  9:06 ` Marek Vasut
  2026-04-17  8:14 ` Mattijs Korpershoek
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Vasut @ 2026-04-16  9:06 UTC (permalink / raw)
  To: Gurumoorthy Santhakumar, trini, mkorpershoek, macromorgan,
	casey.connolly, quic_varada, felipe.balbi, u-boot

On 4/16/26 7:55 AM, Gurumoorthy Santhakumar wrote:
> In dwc3_free_one_event_buffer(), only the DMA buffer (evt->buf) was
> being freed via dma_free_coherent(), but the evt structure itself was
> never explicitly freed, causing a memory leak.
> 
> In dwc3_free_event_buffers(), the ev_buffs pointer array allocated
> with memalign() was never freed after iterating and releasing all
> individual event buffers, causing another memory leak.
> 
> Fix both leaks by freeing the evt struct in
> dwc3_free_one_event_buffer() and freeing dwc->ev_buffs in
> dwc3_free_event_buffers() after all entries have been released.
> 
> Signed-off-by: Gurumoorthy Santhakumar <gurumoorthy.santhakumar@oss.qualcomm.com>

Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>

Thank you

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

* Re: [PATCH v2] usb: dwc3: core: fix memory leaks in event buffer cleanup
  2026-04-16  5:55 [PATCH v2] usb: dwc3: core: fix memory leaks in event buffer cleanup Gurumoorthy Santhakumar
  2026-04-16  9:06 ` Marek Vasut
@ 2026-04-17  8:14 ` Mattijs Korpershoek
  1 sibling, 0 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2026-04-17  8:14 UTC (permalink / raw)
  To: Gurumoorthy Santhakumar, marex, trini, mkorpershoek, macromorgan,
	casey.connolly, quic_varada, felipe.balbi,
	gurumoorthy.santhakumar, u-boot

Hi Gurumoorthy,

Thank you for the patch.

On Thu, Apr 16, 2026 at 11:25, Gurumoorthy Santhakumar <gurumoorthy.santhakumar@oss.qualcomm.com> wrote:

> In dwc3_free_one_event_buffer(), only the DMA buffer (evt->buf) was
> being freed via dma_free_coherent(), but the evt structure itself was
> never explicitly freed, causing a memory leak.
>
> In dwc3_free_event_buffers(), the ev_buffs pointer array allocated
> with memalign() was never freed after iterating and releasing all
> individual event buffers, causing another memory leak.
>
> Fix both leaks by freeing the evt struct in
> dwc3_free_one_event_buffer() and freeing dwc->ev_buffs in
> dwc3_free_event_buffers() after all entries have been released.
>
> Signed-off-by: Gurumoorthy Santhakumar <gurumoorthy.santhakumar@oss.qualcomm.com>

Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>


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

end of thread, other threads:[~2026-04-17  8:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16  5:55 [PATCH v2] usb: dwc3: core: fix memory leaks in event buffer cleanup Gurumoorthy Santhakumar
2026-04-16  9:06 ` Marek Vasut
2026-04-17  8:14 ` Mattijs Korpershoek

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