From: sashiko-bot@kernel.org
To: "Guomin chen" <chenguoming88s@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v3] usb: cdns3: fix NULL dereference in cdns_host_resume()
Date: Mon, 23 Nov 2026 04:56:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-228681@kernel.org> (raw)
In-Reply-To: <20261123044347.3273-1-chenguoming88s@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: cdns3: dangling cdns->host_dev on __cdns_host_init()
error paths
--
commit 65a7dd0ee7f8dab7d9774ef07f61af4db003e801
Author: Guoming Chen <chenguoming88s@gmail.com>
usb: cdns3: fix NULL dereference in cdns_host_resume()
This commit adds NULL checks for cdns->host_dev and its driver data in
cdns_host_resume() to avoid a NULL pointer dereference when the parent
resumes before the xhci-hcd child device has been probed or after host
role startup fails.
> diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c
> index e01264dc625da..2f430e1e00897 100644
> --- a/drivers/usb/cdns3/host.c
> +++ b/drivers/usb/cdns3/host.c
> @@ -140,9 +140,23 @@ static void cdns_host_exit(struct cdns *cdns)
>
> static int cdns_host_resume(struct cdns *cdns, bool power_lost)
> {
> - struct usb_hcd *hcd = platform_get_drvdata(cdns->host_dev);
> - struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> -
> + struct usb_hcd *hcd;
> + struct xhci_plat_priv *priv;
> +
> + /*
> + * The xhci-hcd child may not be bound yet: cdns3 creates it, but
> + * xhci-plat probes it only later, and the drvdata is set in that
> + * probe. cdns->host_dev itself can be NULL, e.g. when the host
> + * role failed to start.
> + */
> + if (!cdns->host_dev)
> + return 0;
> +
> + hcd = platform_get_drvdata(cdns->host_dev);
> + if (!hcd)
> + return 0;
[Severity: Medium]
Is cdns->host_dev guaranteed to be NULL when the host role fails to start?
__cdns_host_init() assigns cdns->host_dev immediately after
platform_device_alloc() and does not clear it on the subsequent error
paths:
drivers/usb/cdns3/host.c:__cdns_host_init() {
...
xhci->dev.parent = cdns->dev;
cdns->host_dev = xhci;
ret = platform_device_add_resources(xhci, cdns->xhci_res,
CDNS_XHCI_RESOURCES_NUM);
if (ret) {
dev_err(cdns->dev, "couldn't add resources to xHCI device\n");
goto err1;
}
...
free_memory:
kfree(cdns->xhci_plat_data);
err1:
platform_device_put(xhci);
return ret;
}
If platform_device_add_resources(), kmemdup(), platform_device_add_data()
or platform_device_add() fails after cdns_role_start() has set
cdns->role = USB_ROLE_HOST, platform_device_put(xhci) frees the device
while cdns->host_dev remains non-NULL. A subsequent cdns_host_resume()
will bypass the !cdns->host_dev check and pass the dangling pointer to
platform_get_drvdata(cdns->host_dev), causing a use-after-free.
Assigning cdns->host_dev only after platform_device_add() succeeds (or
clearing cdns->host_dev = NULL under err1) would ensure the new NULL check
catches all host-init failures.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123044347.3273-1-chenguoming88s@gmail.com?part=1
prev parent reply other threads:[~2026-11-23 4:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 4:43 [PATCH v3] usb: cdns3: fix NULL dereference in cdns_host_resume() Guomin chen
2026-11-23 4:56 ` sashiko-bot [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=sashiko-outbox-228681@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chenguoming88s@gmail.com \
--cc=linux-usb@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox