U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@nabladev.com>
To: Andrew Goodbody <andrew.goodbody@linaro.org>,
	Mattijs Korpershoek <mkorpershoek@kernel.org>,
	Tom Rini <trini@konsulko.com>,
	"vigneshr@ti.com" <vigneshr@ti.com>,
	Siddharth Vadapalli <s-vadapalli@ti.com>
Cc: u-boot@lists.denx.de
Subject: Re: [PATCH] usb: cdns3: Do not access memory after free
Date: Thu, 14 Aug 2025 05:21:33 +0200	[thread overview]
Message-ID: <b83f79a7-66e9-43b9-859e-ebb69e4d536b@nabladev.com> (raw)
In-Reply-To: <20250813-usb_cdns3-v1-1-3779912fe660@linaro.org>

On 8/13/25 6:30 PM, Andrew Goodbody wrote:
> The call to cdns3_gadget_ep_free_request will free priv_req so do the
> call to list_del_init which accesses the memory pointed to by priv_req
> before the free.
> 
> This issue was found by Smatch.
> 
> Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
> ---
>   drivers/usb/cdns3/gadget.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
> index a30c40ef80e..9eaf7e40ab6 100644
> --- a/drivers/usb/cdns3/gadget.c
> +++ b/drivers/usb/cdns3/gadget.c
> @@ -557,10 +557,10 @@ static void cdns3_wa2_remove_old_request(struct cdns3_endpoint *priv_ep)
>   
>   		trace_cdns3_wa2(priv_ep, "removes eldest request");
>   
> +		list_del_init(&priv_req->list);
>   		kfree(priv_req->request.buf);
>   		cdns3_gadget_ep_free_request(&priv_ep->endpoint,
>   					     &priv_req->request);
> -		list_del_init(&priv_req->list);

Shouldn't the kfree() be moved here instead ? 
cdns3_gadget_ep_free_request() also accesses priv_req->request .

>   		--priv_ep->wa2_counter;
>   
>   		if (!chain)
> @@ -1959,10 +1959,10 @@ static int cdns3_gadget_ep_disable(struct usb_ep *ep)
>   	while (!list_empty(&priv_ep->wa2_descmiss_req_list)) {
>   		priv_req = cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list);
>   
> +		list_del_init(&priv_req->list);
>   		kfree(priv_req->request.buf);
>   		cdns3_gadget_ep_free_request(&priv_ep->endpoint,
>   					     &priv_req->request);
> -		list_del_init(&priv_req->list);

DTTO ?

  reply	other threads:[~2025-08-14  4:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13 16:30 [PATCH] usb: cdns3: Do not access memory after free Andrew Goodbody
2025-08-14  3:21 ` Marek Vasut [this message]
2025-08-14 10:45   ` Andrew Goodbody
2025-08-19 14:51     ` Marek Vasut
2025-08-21  6:16       ` Siddharth Vadapalli
2025-08-21 20:22         ` Marek Vasut
2025-08-22 14:14           ` Siddharth Vadapalli
2025-08-22 14:55             ` Marek Vasut
2025-08-23  2:07               ` Siddharth Vadapalli
2025-08-23 12:21                 ` Marek Vasut
2025-08-24  8:02                   ` Siddharth Vadapalli
2025-08-28 15:46                     ` Marek Vasut
2025-08-29  4:22                       ` Siddharth Vadapalli
2025-08-29  8:49                         ` Marek Vasut

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=b83f79a7-66e9-43b9-859e-ebb69e4d536b@nabladev.com \
    --to=marex@nabladev.com \
    --cc=andrew.goodbody@linaro.org \
    --cc=mkorpershoek@kernel.org \
    --cc=s-vadapalli@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /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