From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Guomin chen" <chenguoming88s@gmail.com>,
"Peter Chen" <peter.chen@kernel.org>,
"Pawel Laszczak" <pawell@cadence.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: "Roger Quadros" <rogerq@kernel.org>, <linux-usb@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH v4] usb: cdns3: fix NULL dereference in cdns_host_resume()
Date: Mon, 23 Nov 2026 12:07:21 +0100 [thread overview]
Message-ID: <DN2JJHBVAPCY.2CNUCGCO781D6@bootlin.com> (raw)
In-Reply-To: <20261123075116.3868-1-chenguoming88s@gmail.com>
Hello Guomin,
On Mon Nov 23, 2026 at 8:51 AM CET, Guomin chen wrote:
> From: Guoming Chen <chenguoming88s@gmail.com>
>
> cdns_host_resume() assumes that the xhci-hcd child is bound and passes
> platform_get_drvdata() to hcd_to_xhci_priv() unchecked. The child is
> created by __cdns_host_init(), but xhci-plat probes it only when it
> registers; cdns3/ precedes host/ in drivers/usb/Makefile, so with both
> built in the child is registered before xhci-plat's initcall runs, and
> with xhci-plat as a module it stays unbound until the module loads.
> Platforms that allow runtime PM (cdns3-imx is the only in-tree user)
> autosuspend the controller after 20 ms, so the parent may already be
> suspended when the child is probed.
>
> Resuming the parent, either for the child's probe
> (__driver_probe_device() calls pm_runtime_get_sync(dev->parent)) or on
> a system-wide resume, runs cdns_host_resume() while the drvdata is
> still NULL; xhci_plat_probe() sets it later via __usb_create_hcd().
> hcd_to_xhci_priv(NULL) then dereferences NULL + offsetof(struct
> usb_hcd, primary_hcd):
>
> pc : usb_hcd_is_primary_hcd+0x0/0x1c
> lr : cdns_host_resume+0x24/0x44
>
> Commit 87e4b043b98a ("usb: cdns3: fix role switching during resume")
> only skips the callback when the role changes during resume, which is
> not the case here.
>
> Return early when there is no hcd to notify: the host role can fail to
> start after cdns_role_start() set cdns->role, or the child may not be
> probed yet. An unbound child has no state to restore, power_lost is
> only consumed by an initialized host, and cdns_wakeup_irq() already
> checks cdns->host_dev the same way. Also publish cdns->host_dev only
> after platform_device_add() succeeds: the error paths free the child
> with platform_device_put() while the pointer stays set, and the next
> resume would dereference freed memory instead of bailing out.
Your commit is too long and robotic; didn't read!
Reading the patch, you protect against two things:
- cdns->host_dev == NULL
- platform_get_drvdata(cdns->host_dev) == NULL
Your commit message should say that out loud and give an exact way for
those two to occur. It should also mention the hardware used to
reproduce the issue, with full kernel panic log.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
prev parent reply other threads:[~2026-11-23 11:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 4:43 [PATCH v3] " Guomin chen
2026-11-23 7:51 ` [PATCH v4] " Guomin chen
2026-11-23 11:07 ` Théo Lebrun [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=DN2JJHBVAPCY.2CNUCGCO781D6@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=chenguoming88s@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pawell@cadence.com \
--cc=peter.chen@kernel.org \
--cc=rogerq@kernel.org \
--cc=stable@vger.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 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®