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 3/5] usb: dwc2: hcd: fix possible successive vbus supply enables
Date: Thu, 08 Oct 2026 14:01:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-164260@kernel.org> (raw)
In-Reply-To: <20261008-dwc2-low-power-fixes-stm32-v1-3-5b303df762e6@foss.st.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] usb: dwc2: regulator leak due to symmetric XOR logic
--

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

usb: dwc2: hcd: fix possible successive vbus supply enables

External VBUS supply may have already been enabled, before entering
dwc2_hcd_reinit. This results in vbus enable count to increase every
time this occurs, and dwc2_vbus_supply_exit won't disable vbus upon
suspend request. Fix this by reading PWR bit before and after
dwc2_hcd_reinit() call.

> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index d5275cd658d4c..b7b4ff466d2b5 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -4264,9 +4264,11 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
>  		return 0;	/* why 0 ?? */
>  	}
>  
> +	hprt0 = dwc2_read_hprt0(hsotg);
> +
>  	dwc2_hcd_reinit(hsotg);
>  
> -	hprt0 = dwc2_read_hprt0(hsotg);
> +	hprt0 ^= dwc2_read_hprt0(hsotg);
>  	/* Has vbus power been turned on in dwc2_core_host_init ? */
>  	if (hprt0 & HPRT0_PWR) {
>  		/* Enable external vbus supply before resuming root hub */
>  		spin_unlock_irqrestore(&hsotg->lock, flags);
>  		ret = dwc2_vbus_supply_init(hsotg);

[Severity: Medium]
Since this XOR operation is symmetric, does it also evaluate to true if
HPRT0_PWR transitions from 1 to 0?

A 1 to 0 transition seems structurally possible if the hardware
asynchronously clears the power bit (e.g. due to an overcurrent fault
HPRT0_OVRCURRCHG) during the execution window.

If this occurs, could the driver erroneously call dwc2_vbus_supply_init()
when power was lost, improperly incrementing the regulator enable count?

Later cleanup paths like dwc2_hcd_stop() or ClearPortFeature
USB_PORT_FEAT_POWER will observe HPRT0_PWR == 0 and skip calling
dwc2_vbus_supply_exit(), which appears to lead to a permanent regulator
use count leak. The issue is not fixed in subsequent patches in the series.

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

  reply	other threads:[~2026-10-08 14:01 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
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 [this message]
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-164260@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.