All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Prashanth K" <prashanth.k@oss.qualcomm.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: host: Mark dwc->xhci as null if xhci probe fails
Date: Wed, 14 Oct 2026 11:07:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-171174@kernel.org> (raw)
In-Reply-To: <20261014105711.1708244-1-prashanth.k@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb: dwc3: NULL pointer offset dereference in dwc3_host_exit() during role switch
--

commit 24753f0ba9a09a8a782231f3b06d19d819bc300c
Author: Prashanth K <prashanth.k@oss.qualcomm.com>

usb: dwc3: host: Mark dwc->xhci as null if xhci probe fails

Currently dwc->xhci is not cleared when xhci_plat_probe fails, leading to a
use-after-free or null pointer dereference later. This commit sets the
pointer to NULL in the error path of dwc3_host_init() to prevent this issue.

> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
> index c5674161b2b08..b01cf49454c2e 100644
> --- a/drivers/usb/dwc3/host.c
> +++ b/drivers/usb/dwc3/host.c
> @@ -219,6 +219,7 @@ int dwc3_host_init(struct dwc3 *dwc)
>  	return 0;
>  err:
>  	platform_device_put(xhci);
> +	dwc->xhci = NULL;

[Severity: High]
Could this lead to an invalid pointer dereference during subsequent role
switches?

In drivers/usb/dwc3/core.c:__dwc3_set_mode(), the role is updated to host mode
before dwc3_host_init() is called, and is never reverted on failure:

__dwc3_set_mode() {
    ...
    dwc3_set_prtcap(dwc, mode);
    dwc->current_dr_role = mode;
    ...
    ret = dwc3_host_init(dwc);
    ...
}

If dwc3_host_init() fails, the role remains set to host mode, and dwc->xhci
is now explicitly NULL. When the system later attempts to switch roles (e.g.,
back to device mode), __dwc3_set_mode() evaluates dwc->current_dr_role and
invokes dwc3_host_exit(dwc). 

Inside dwc3_host_exit(), if dwc->sys_wakeup is true, it unconditionally
evaluates the address of dev inside xhci:

dwc3_host_exit() {
    ...
    if (dwc->sys_wakeup)
        device_init_wakeup(&dwc->xhci->dev, false);
    ...
}

Because dwc->xhci is NULL, &dwc->xhci->dev evaluates to a small non-zero
offset. This bypasses the !dev check inside device_init_wakeup() and can
cause a fault when attempting to read dev->power.can_wakeup.

>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(dwc3_host_init);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261014105711.1708244-1-prashanth.k@oss.qualcomm.com?part=1

  reply	other threads:[~2026-10-14 11:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 10:57 [PATCH] usb: dwc3: host: Mark dwc->xhci as null if xhci probe fails Prashanth K
2026-10-14 11:07 ` sashiko-bot [this message]
2026-10-14 11:17 ` Greg Kroah-Hartman
2026-10-14 11:25   ` Prashanth K

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=sashiko-outbox-171174@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=prashanth.k@oss.qualcomm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.