From: Greg KH <gregkh@linuxfoundation.org>
To: Haoxiang Li <haoxiang_li2024@163.com>
Cc: kees@kernel.org, balbi@ti.com, sebastian@breakpoint.cc,
linux-usb@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org, stable@kernel.org
Subject: Re: [PATCH] usb: gadget: fsl_qe_udc: fix gadget lifetime on registration failure
Date: Thu, 25 Jun 2026 15:55:27 +0100 [thread overview]
Message-ID: <2026062552-danger-slug-bc0d@gregkh> (raw)
In-Reply-To: <20260622140610.1140558-1-haoxiang_li2024@163.com>
On Mon, Jun 22, 2026 at 10:06:10PM +0800, Haoxiang Li wrote:
> usb_add_gadget_udc_release() drops the gadget device reference when
> registration fails. This invokes qe_udc_release() while qe_udc_probe()
> is still unwinding. Since udc->done is not initialized during probe,
> the release callback dereferences NULL in complete(). It also frees
> the qe_udc object before the remaining probe cleanup accesses it,
> resulting in use-after-free and double-free risks.
>
> Initialize the gadget device explicitly and register it with
> usb_add_gadget(), which leaves the gadget reference owned by the
> driver on failure. Unwind the IRQ, DMA mappings, endpoint resources
> and registers before dropping that reference with usb_put_gadget().
> Make the completion notification conditional because it is only
> installed by the remove path.
>
> Similarly, use usb_del_gadget() during removal so the final gadget
> reference remains held while the controller resources are released.
> Set the completion pointer immediately before dropping the reference,
> then wait for the release callback to finish.
>
> Fixes: d77c1198666d ("usb: gadget: fsl_qe_udc: convert to new style start/stop")
> Cc: stable@kernel.org
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
> drivers/usb/gadget/udc/fsl_qe_udc.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c b/drivers/usb/gadget/udc/fsl_qe_udc.c
> index bf87285ad13c..f9a59b32e272 100644
> --- a/drivers/usb/gadget/udc/fsl_qe_udc.c
> +++ b/drivers/usb/gadget/udc/fsl_qe_udc.c
> @@ -2459,7 +2459,9 @@ static void qe_udc_release(struct device *dev)
> struct qe_udc *udc = container_of(dev, struct qe_udc, gadget.dev);
> int i;
>
> - complete(udc->done);
> + if (udc->done)
> + complete(udc->done);
> +
> cpm_muram_free(cpm_muram_offset(udc->ep_param[0]));
> for (i = 0; i < USB_MAX_ENDPOINTS; i++)
> udc->ep_param[i] = NULL;
> @@ -2489,6 +2491,9 @@ static int qe_udc_probe(struct platform_device *ofdev)
> return -ENOMEM;
> }
>
> + usb_initialize_gadget(&ofdev->dev, &udc->gadget,
> + qe_udc_release);
Odd coding style, why not just one line?
thanks,
greg k-h
prev parent reply other threads:[~2026-06-25 14:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 14:06 [PATCH] usb: gadget: fsl_qe_udc: fix gadget lifetime on registration failure Haoxiang Li
2026-06-25 14:55 ` Greg KH [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=2026062552-danger-slug-bc0d@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=balbi@ti.com \
--cc=haoxiang_li2024@163.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=sebastian@breakpoint.cc \
--cc=stable@kernel.org \
/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 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.