* [PATCH v2] usb: cdns3: fix NULL dereference in cdns_host_resume()
@ 2026-11-18 14:05 Guomin chen
2026-11-20 15:37 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Guomin chen @ 2026-11-18 14:05 UTC (permalink / raw)
To: Peter Chen, Pawel Laszczak, Greg Kroah-Hartman
Cc: Roger Quadros, linux-usb, linux-kernel, Guoming Chen
From: Guoming Chen <chenguoming88s@gmail.com>
cdns_host_resume() assumes that the xhci-hcd child device is bound and
passes platform_get_drvdata() straight to hcd_to_xhci_priv(). That is
not guaranteed: __cdns_host_init() creates the child with
platform_device_add(), but the child is only probed once xhci-plat
registers. cdns3/ is linked before host/ in drivers/usb/Makefile and
both are module_init(), so at boot the child stays unbound until
xhci-plat's initcall runs; when xhci-plat is a module it stays unbound
until the module is loaded, and it is retried even later when its probe
returns -EPROBE_DEFER. Platforms that set
CDNS3_DEFAULT_PM_RUNTIME_ALLOW (cdns3-imx is the only in-tree user) let
the controller autosuspend (20 ms), so the parent may already be
runtime-suspended by the time the child's probe actually runs.
When the child is finally probed, driver core resumes its parent before
calling really_probe() (pm_runtime_get_sync(dev->parent) in
__driver_probe_device()). That runs cdns_resume() ->
cdns_host_resume() while platform_get_drvdata() still returns NULL,
because the drvdata is only set later, by dev_set_drvdata() in
__usb_create_hcd() called from xhci_plat_probe(). hcd_to_xhci_priv(NULL)
then evaluates usb_hcd_is_primary_hcd(NULL), which dereferences
NULL + offsetof(struct usb_hcd, primary_hcd) (the offset depends on the
configuration). The oops faults in the first instruction of that
helper:
pc : usb_hcd_is_primary_hcd+0x0/0x1c
lr : cdns_host_resume+0x24/0x44
Return early when the host child is not available: it has either not
been created yet or not been probed. cdns->host_dev is also cleared by
cdns_host_exit() while cdns_role_stop() leaves cdns->role pointing at
the host role, so a resume after a role stop reaches this function as
well. Nothing is lost in either case: the child's probe initializes the
controller from scratch, and xhci_plat_priv.power_lost is only consumed
when an already initialized host resumes.
Fixes: 3a85c1011540 ("usb: host: cdns3: forward lost power information to xhci")
Signed-off-by: Guoming Chen <chenguoming88s@gmail.com>
---
drivers/usb/cdns3/host.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c
index e01264dc625d..3456f065111b 100644
--- a/drivers/usb/cdns3/host.c
+++ b/drivers/usb/cdns3/host.c
@@ -140,9 +140,21 @@ 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 (xhci-plat can probe it
+ * after cdns3 created it), or may already be gone after a role stop.
+ */
+ if (!cdns->host_dev)
+ return 0;
+
+ hcd = platform_get_drvdata(cdns->host_dev);
+ if (!hcd)
+ return 0;
+ priv = hcd_to_xhci_priv(hcd);
priv->power_lost = power_lost;
return 0;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] usb: cdns3: fix NULL dereference in cdns_host_resume()
2026-11-18 14:05 [PATCH v2] usb: cdns3: fix NULL dereference in cdns_host_resume() Guomin chen
@ 2026-11-20 15:37 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-20 15:37 UTC (permalink / raw)
To: Guomin chen
Cc: Peter Chen, Pawel Laszczak, Roger Quadros, linux-usb, linux-kernel
On Wed, Nov 18, 2026 at 10:05:13PM +0800, Guomin chen wrote:
> From: Guoming Chen <chenguoming88s@gmail.com>
>
> cdns_host_resume() assumes that the xhci-hcd child device is bound and
> passes platform_get_drvdata() straight to hcd_to_xhci_priv(). That is
> not guaranteed: __cdns_host_init() creates the child with
> platform_device_add(), but the child is only probed once xhci-plat
> registers. cdns3/ is linked before host/ in drivers/usb/Makefile and
> both are module_init(), so at boot the child stays unbound until
> xhci-plat's initcall runs; when xhci-plat is a module it stays unbound
> until the module is loaded, and it is retried even later when its probe
> returns -EPROBE_DEFER. Platforms that set
> CDNS3_DEFAULT_PM_RUNTIME_ALLOW (cdns3-imx is the only in-tree user) let
> the controller autosuspend (20 ms), so the parent may already be
> runtime-suspended by the time the child's probe actually runs.
>
> When the child is finally probed, driver core resumes its parent before
> calling really_probe() (pm_runtime_get_sync(dev->parent) in
> __driver_probe_device()). That runs cdns_resume() ->
> cdns_host_resume() while platform_get_drvdata() still returns NULL,
> because the drvdata is only set later, by dev_set_drvdata() in
> __usb_create_hcd() called from xhci_plat_probe(). hcd_to_xhci_priv(NULL)
> then evaluates usb_hcd_is_primary_hcd(NULL), which dereferences
> NULL + offsetof(struct usb_hcd, primary_hcd) (the offset depends on the
> configuration). The oops faults in the first instruction of that
> helper:
>
> pc : usb_hcd_is_primary_hcd+0x0/0x1c
> lr : cdns_host_resume+0x24/0x44
>
> Return early when the host child is not available: it has either not
> been created yet or not been probed. cdns->host_dev is also cleared by
> cdns_host_exit() while cdns_role_stop() leaves cdns->role pointing at
> the host role, so a resume after a role stop reaches this function as
> well. Nothing is lost in either case: the child's probe initializes the
> controller from scratch, and xhci_plat_priv.power_lost is only consumed
> when an already initialized host resumes.
>
> Fixes: 3a85c1011540 ("usb: host: cdns3: forward lost power information to xhci")
> Signed-off-by: Guoming Chen <chenguoming88s@gmail.com>
> ---
> drivers/usb/cdns3/host.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c
> index e01264dc625d..3456f065111b 100644
> --- a/drivers/usb/cdns3/host.c
> +++ b/drivers/usb/cdns3/host.c
> @@ -140,9 +140,21 @@ 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 (xhci-plat can probe it
> + * after cdns3 created it), or may already be gone after a role stop.
> + */
> + if (!cdns->host_dev)
> + return 0;
> +
> + hcd = platform_get_drvdata(cdns->host_dev);
> + if (!hcd)
> + return 0;
>
> + priv = hcd_to_xhci_priv(hcd);
> priv->power_lost = power_lost;
>
> return 0;
> --
> 2.43.0
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 15:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 14:05 [PATCH v2] usb: cdns3: fix NULL dereference in cdns_host_resume() Guomin chen
2026-11-20 15:37 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®