From: sashiko-bot@kernel.org
To: "Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v6 03/11] usb: dwc2: drop stale state after register restore on resume
Date: Wed, 25 Nov 2026 17:09:33 +0000 [thread overview]
Message-ID: <sashiko-outbox-233810@kernel.org> (raw)
In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-3-d5df33b93eaf@foss.st.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: dwc2: stale backup valid flags left set in dwc2_resume()
when not lost
--
commit 4c1dd5f40e80c2ddc45f465c1df3b944bef53d8d
Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
usb: dwc2: drop stale state after register restore on resume
This commit adds dwc2_clear_lost_state() and uses it in device and host
mode resume paths to clear stale software state when register loss is
detected after a power domain off.
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index 7f3436e6a1538..53c34a42f7600 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -738,6 +738,7 @@ static int __maybe_unused dwc2_resume(struct device *dev)
> {
> struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
> unsigned long flags;
> + bool lost;
> int ret = 0;
>
> if (!dwc2->ll_hw_enabled)
> @@ -788,16 +789,29 @@ static int __maybe_unused dwc2_resume(struct device *dev)
> * In case the GUSBCFG register is not initialized, it's clear the
> * registers must be restored.
> */
> - if (!(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK)) {
> + lost = !(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK);
> + if (lost) {
> spin_lock_irqsave(&dwc2->lock, flags);
> ret = dwc2_restore_critical_registers(dwc2);
> + /*
> + * The restore re-enables global interrupts: keep them off
> + * until the stale state is cleaned up below.
> + */
> + if (!ret)
> + dwc2_disable_global_interrupts(dwc2);
> spin_unlock_irqrestore(&dwc2->lock, flags);
> if (ret)
> return ret;
> }
>
> if (dwc2_is_device_mode(dwc2))
> - ret = dwc2_hsotg_resume(dwc2);
> + ret = dwc2_hsotg_resume(dwc2, lost);
> + else if (lost)
> + dwc2_hcd_lost_state(dwc2);
[Severity: Medium]
Does skipping dwc2_clear_lost_state() when lost is false leave
gr_backup.valid and dr_backup.valid (or hr_backup.valid) set after a
suspend/resume cycle where the power domain stayed on?
When the controller is not already in a low-power state at system suspend
(for instance in device mode at DWC2_L0, where dwc2_hsotg_suspend() puts
it into DWC2_L3), dwc2_suspend() backs up the registers and sets the
backup valid flags:
drivers/usb/dwc2/platform.c:dwc2_suspend() {
...
gr = &dwc2->gr_backup;
if (!gr->valid) {
if (is_device_mode)
ret = dwc2_gadget_backup_critical_registers(dwc2);
else
ret = dwc2_host_backup_critical_registers(dwc2);
}
...
}
If the power domain is not powered off during that suspend (such as s2idle
or standby), lost is false on resume. In device mode,
dwc2_hsotg_resume(dwc2, false) reinitializes the core to DWC2_L0 without
calling dwc2_restore_critical_registers() or dwc2_clear_lost_state(),
leaving gr_backup.valid and dr_backup.valid true. Any subsequent
dwc2_suspend() will then see gr->valid == true and skip backing up the
current registers, so a later suspend that does lose power will restore
stale state from the earlier cycle (or fail to restore if the OTG role
changed in between).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com?part=3
next prev parent reply other threads:[~2026-11-25 17:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 16:32 [PATCH v6 00/11] usb: dwc2: fix low power issues found on stm32mp1 Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 01/11] usb: dwc2: fix recovery after PM domain off Fabrice Gasnier
2026-11-25 16:58 ` sashiko-bot
2026-11-25 16:32 ` [PATCH v6 02/11] usb: dwc2: keep TOUTCAL canary valid after PHY init Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 03/11] usb: dwc2: drop stale state after register restore on resume Fabrice Gasnier
2026-11-25 17:09 ` sashiko-bot [this message]
2026-11-25 16:32 ` [PATCH v6 04/11] usb: dwc2: clean up old role on mode change during suspend Fabrice Gasnier
2026-11-25 16:57 ` sashiko-bot
2026-11-25 16:32 ` [PATCH v6 05/11] usb: dwc2: fix a possible interrupt storm in hcd resume Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 06/11] usb: dwc2: fix a possible interrupt storm on stm32mp1 Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 07/11] usb: dwc2: hcd: fix possible successive vbus supply enables Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 08/11] usb: dwc2: hcd: don't disable external vbus in system suspend Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 09/11] usb: dwc2: restore peripheral mode on low-level enable Fabrice Gasnier
2026-11-25 17:08 ` sashiko-bot
2026-11-25 16:32 ` [PATCH v6 10/11] usb: dwc2: platform: fix stm32mp15 detection logic power management Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 11/11] usb: dwc2: drop redundant ll_hw_enabled checks in suspend/resume Fabrice Gasnier
2026-11-25 17:09 ` [PATCH v6 00/11] usb: dwc2: fix low power issues found on stm32mp1 sashiko-bot
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-233810@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fabrice.gasnier@foss.st.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 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.