All of lore.kernel.org
 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 v5 6/7] usb: dwc2: restore peripheral mode on low-level enable
Date: Tue, 17 Nov 2026 17:31:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-219235@kernel.org> (raw)
In-Reply-To: <20261117-dwc2-low-power-fixes-stm32-v5-6-0f197e0e6362@foss.st.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: dwc2: missing mode and role-switch restore in
  __dwc2_lowlevel_hw_enable()
--

commit 4a34cd28e14c0cab3dbb4e8a1ede5ebdce1b30e7
Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

usb: dwc2: restore peripheral mode on low-level enable

This commit restores the configured peripheral mode in
__dwc2_lowlevel_hw_enable() when no role switch is registered and skips
the duplicate peripheral restore in dwc2_resume().

> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index 3bdb889028117..5fd005e721732 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -129,6 +129,14 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
>  	if (ret)
>  		goto err_dis_clk;
>  
> +	if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL && !hsotg->role_sw) {
> +		/*
> +		 * Gadget code manages low-level hardware on its own. Restore
> +		 * peripheral mode after register loss while it was disabled.
> +		 */
> +		dwc2_force_dr_mode(hsotg);
> +	}
> +
>  	return 0;

[Severity: Medium]
Does excluding hsotg->role_sw here leave forced device mode and the
role-switch session override bits uninitialized after standby when
peripheral mode is used with a usb-role-switch?

dwc2_driver_probe() and dwc2_hsotg_udc_stop() disable low-level hardware
whenever dr_mode is peripheral, even when hsotg->role_sw is present.  If
the controller loses its registers during standby while no gadget driver
is bound, dwc2_resume() returns early because ll_hw_enabled is false,
skipping dwc2_drd_resume().

When a gadget driver is later bound and __dwc2_lowlevel_hw_enable() runs,
!hsotg->role_sw skips the restore here as well, and role-switch updates
do not force the mode in peripheral configurations:

drivers/usb/dwc2/drd.c:dwc2_drd_role_sw_set() {
    ...
	if (!already && hsotg->dr_mode == USB_DR_MODE_OTG)
		/* This will raise a Connector ID Status Change Interrupt */
		dwc2_force_mode(hsotg, role == USB_ROLE_HOST);
    ...
}

Without forcing device mode and restoring the B-session valid override,
dwc2_hsotg_core_connect() sees no valid B-session and leaves soft
disconnect asserted, breaking USB peripheral enumeration.  Calling
dwc2_drd_resume(hsotg) when hsotg->role_sw is set would restore both the
session overrides and the forced mode.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-dwc2-low-power-fixes-stm32-v5-0-0f197e0e6362@foss.st.com?part=6

  reply	other threads:[~2026-11-17 17:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:06 [PATCH v5 0/7] usb: dwc2: fix low power issues found on stm32mp1 Fabrice Gasnier
2026-11-17 17:06 ` [PATCH v5 1/7] usb: dwc2: fix recovery after PM domain off Fabrice Gasnier
2026-11-17 17:42   ` sashiko-bot
2026-11-17 17:06 ` [PATCH v5 2/7] usb: dwc2: fix a possible interrupt storm in hcd resume Fabrice Gasnier
2026-11-17 17:14   ` sashiko-bot
2026-11-17 17:06 ` [PATCH v5 3/7] usb: dwc2: fix a possible interrupt storm on stm32mp1 Fabrice Gasnier
2026-11-17 17:15   ` sashiko-bot
2026-11-17 17:06 ` [PATCH v5 4/7] usb: dwc2: hcd: fix possible successive vbus supply enables Fabrice Gasnier
2026-11-17 17:15   ` sashiko-bot
2026-11-17 17:06 ` [PATCH v5 5/7] usb: dwc2: hcd: don't disable external vbus in system suspend Fabrice Gasnier
2026-11-17 17:15   ` sashiko-bot
2026-11-17 17:06 ` [PATCH v5 6/7] usb: dwc2: restore peripheral mode on low-level enable Fabrice Gasnier
2026-11-17 17:31   ` sashiko-bot [this message]
2026-11-17 17:06 ` [PATCH v5 7/7] usb: dwc2: platform: fix stm32mp15 detection logic power management Fabrice Gasnier
2026-11-17 17:32   ` 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-219235@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.