Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 1/5] usb: dwc2: fix recovery after PM domain off
Date: Thu, 08 Oct 2026 13:53:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-164252@kernel.org> (raw)
In-Reply-To: <20261008-dwc2-low-power-fixes-stm32-v1-1-5b303df762e6@foss.st.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] usb: dwc2: gadget state lost on system resume with clock gating
- [Medium] usb: dwc2: missing resource cleanup on dwc2_core_init failure
--

commit 0a7c02abb23c7f52b48654e1d1781cd4041fb820
Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Subject: usb: dwc2: fix recovery after PM domain off

This commit modifies the PM suspend and resume recovery mechanism for dwc2
to prevent freezes when reading registers during clock gating. It removes
the manual backup of critical registers during suspend and moves the core
re-initialization logic to dwc2_resume().

> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index ef0d730770347..643d67ce28ea2 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -692,14 +692,6 @@ static int __maybe_unused dwc2_suspend(struct device *dev)
>  		regulator_disable(dwc2->usb33d);
>  	}
>  
> -	if (is_device_mode)
> -		ret = dwc2_gadget_backup_critical_registers(dwc2);
> -	else
> -		ret = dwc2_host_backup_critical_registers(dwc2);
> -
> -	if (ret)
> -		return ret;
> -
>  	if (dwc2->ll_hw_enabled &&
>  	    (is_device_mode || dwc2_host_can_poweroff_phy(dwc2))) {
>  		ret = __dwc2_lowlevel_hw_disable(dwc2);

[ ... ]

> @@ -786,6 +748,22 @@ static int __maybe_unused dwc2_resume(struct device *dev)
>  		dwc2_drd_resume(dwc2);
>  	}
>  
> +	/*
> +	 * During suspend it's possible that the power domain for the
> +	 * DWC2 controller is disabled and all register values get lost.
> +	 * In case the GUSBCFG register is not initialized, it's clear the
> +	 * registers must be restored. So invoke here the necessary init
> +	 * as done by dwc2_hcd_init() during probe.
> +	 */
> +	if (!(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK)) {
> +		if (dwc2->dr_mode != USB_DR_MODE_PERIPHERAL) {

[Severity: High]
Does this leave the USB gadget permanently unresponsive if the USB bus was
suspended by the host prior to system suspend?

Since the manual backup of critical gadget registers was removed from
dwc2_suspend(), the platform cuts power to the controller and wipes all
hardware registers during suspend. On system resume, this check explicitly
skips dwc2_core_init() for pure peripheral mode (USB_DR_MODE_PERIPHERAL).

Subsequently, dwc2_hsotg_resume() is called, which can return early:

drivers/usb/dwc2/gadget.c:dwc2_hsotg_resume() {
	...
	if (hsotg->lx_state == DWC2_L2)
		return 0;
	...
}

Will this cause the device core and endpoints to remain completely
uninitialized since they are never restored or re-initialized?

> +			ret = dwc2_core_init(dwc2, true);
> +			if (ret)
> +				return ret;

[Severity: Medium]
Does this error path leak hardware resources?

Earlier in dwc2_resume(), __dwc2_lowlevel_hw_enable() is called to enable
clocks and regulators. If dwc2_core_init() fails and returns directly here,
does it bypass the required __dwc2_lowlevel_hw_disable() cleanup?

> +			dwc2_enable_global_interrupts(dwc2);
> +		}
> +	}
> +
>  	if (dwc2_is_device_mode(dwc2))
>  		ret = dwc2_hsotg_resume(dwc2);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261008-dwc2-low-power-fixes-stm32-v1-0-5b303df762e6@foss.st.com?part=1

  reply	other threads:[~2026-10-08 13:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 13:33 [PATCH 0/5] usb: dwc2: fix low power issues found on stm32mp1 Fabrice Gasnier
2026-10-08 13:33 ` [PATCH 1/5] usb: dwc2: fix recovery after PM domain off Fabrice Gasnier
2026-10-08 13:53   ` sashiko-bot [this message]
2026-10-08 13:33 ` [PATCH 2/5] usb: dwc2: fix a possible interrupt storm on stm32mp1 Fabrice Gasnier
2026-10-08 13:49   ` sashiko-bot
2026-10-08 13:33 ` [PATCH 3/5] usb: dwc2: hcd: fix possible successive vbus supply enables Fabrice Gasnier
2026-10-08 14:01   ` sashiko-bot
2026-10-08 13:33 ` [PATCH 4/5] usb: dwc2: hcd: don't disable/enable external vbus by system suspend/resume Fabrice Gasnier
2026-10-08 14:04   ` sashiko-bot
2026-10-08 13:33 ` [PATCH 5/5] usb: dwc2: platform: fix stm32mp15 detection logic power management Fabrice Gasnier
2026-10-08 14:13   ` sashiko-bot
2026-10-08 16:43 ` [PATCH 0/5] usb: dwc2: fix low power issues found on stm32mp1 Stefan Wahren

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-164252@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox