Re: [PATCH v2 1/2] usb: dwc3: host: fix dangling xhci pointer on init failure

From: Thinh Nguyen

Date: Fri Sep 11 2026 - 19:12:56 EST


On Sat, Sep 05, 2026, David Collin wrote:
> dwc3_host_init()'s error path frees xhci via platform_device_put()
> but never clears dwc->xhci, leaving a dangling pointer that
> dwc3_host_exit() dereferences unconditionally on removal/shutdown.
> Clear dwc->xhci on the error path and return early from
> dwc3_host_exit() if NULL.
>
> Fixes: d07e8819a03d ("usb: dwc3: add xHCI Host support")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: David Collin <davidcollin899@xxxxxxxxx>
> ---
> drivers/usb/dwc3/host.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
> index c5674161b2b0..74117cbb2f42 100644
> --- a/drivers/usb/dwc3/host.c
> +++ b/drivers/usb/dwc3/host.c
> @@ -219,12 +219,16 @@ int dwc3_host_init(struct dwc3 *dwc)
> return 0;
> err:
> platform_device_put(xhci);
> + dwc->xhci = NULL;
> return ret;
> }
> EXPORT_SYMBOL_GPL(dwc3_host_init);
>
> void dwc3_host_exit(struct dwc3 *dwc)
> {
> + if (!dwc->xhci)
> + return;
> +
> if (dwc->sys_wakeup)
> device_init_wakeup(&dwc->xhci->dev, false);
>
> --
> 2.55.0
>

Acked-by: Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx>

Thanks,
Thinh