U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: Marek Vasut <marex@nabladev.com>,
	Alexey Charkov <alchark@flipper.net>,
	Gurumoorthy Santhakumar
	<gurumoorthy.santhakumar@oss.qualcomm.com>
Cc: marex@denx.de, trini@konsulko.com, mkorpershoek@kernel.org,
	macromorgan@hotmail.com, casey.connolly@linaro.org,
	quic_varada@quicinc.com, felipe.balbi@linux.intel.com,
	u-boot@lists.denx.de
Subject: Re: [PATCH v2] usb: dwc3: core: fix memory leaks in event buffer cleanup
Date: Mon, 11 May 2026 11:05:41 +0200	[thread overview]
Message-ID: <871pfiwc2i.fsf@kernel.org> (raw)
In-Reply-To: <81e67a70-d4f0-4cd3-9dac-824e418599cb@nabladev.com>

Hi Alexey,

Thank you for reporting this issue.

On Fri, May 08, 2026 at 13:26, Marek Vasut <marex@nabladev.com> wrote:

> On 5/8/26 1:01 PM, Alexey Charkov wrote:
>> On Fri, May 8, 2026 at 2:45 PM 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>
>>> ---
>>> 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);
>> 
>> Hi Gurumoorthy,
>> 
>> evt is allocated using devm_kzalloc, so this change introduces a
>> double-free causing a crash when tearing down a USB gadget mode
>> session on my Rockchip RK3576 board:
> Can you please also provide a Tested-by: for this fix ?

As mentioned by Marek, we already have a fix in review for the problem
you have reported.

It's available here:
https://lore.kernel.org/u-boot/20260507-usb-v3-1-402b37fc2154@oss.qualcomm.com/

Can you please test the above patch and reply with a Tested-by: if it
fixes your problem?

      reply	other threads:[~2026-05-11  9:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-05-08 11:01 ` Alexey Charkov
2026-05-08 11:26   ` Marek Vasut
2026-05-11  9:05     ` Mattijs Korpershoek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871pfiwc2i.fsf@kernel.org \
    --to=mkorpershoek@kernel.org \
    --cc=alchark@flipper.net \
    --cc=casey.connolly@linaro.org \
    --cc=felipe.balbi@linux.intel.com \
    --cc=gurumoorthy.santhakumar@oss.qualcomm.com \
    --cc=macromorgan@hotmail.com \
    --cc=marex@denx.de \
    --cc=marex@nabladev.com \
    --cc=quic_varada@quicinc.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox