[PATCH v1] usb: dwc3: core: fix memory leaks in event buffer cleanup
Gurumoorthy Santhakumar
gurumoorthy.santhakumar at oss.qualcomm.com
Tue Apr 14 07:50:13 CEST 2026
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 at oss.qualcomm.com>
---
drivers/usb/dwc3/core.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 6f22b9232ba..e0c4cb64c48 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -206,6 +206,11 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
struct dwc3_event_buffer *evt)
{
dma_free_coherent(evt->buf);
+
+ if (evt) {
+ free(evt);
+ evt = NULL;
+ }
}
/**
@@ -252,6 +257,11 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc)
if (evt)
dwc3_free_one_event_buffer(dwc, evt);
}
+
+ if (dwc->ev_buffs) {
+ free(dwc->ev_buffs);
+ dwc->ev_buffs = NULL;
+ }
}
/**
--
2.34.1
More information about the U-Boot
mailing list