The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] usb: typec: hd3ss3220: track VBUS enable state per consumer
@ 2026-08-19 15:20 Chang Wu
  2026-08-24 11:20 ` Heikki Krogerus
  2026-08-25 12:39 ` Jan Remmet
  0 siblings, 2 replies; 3+ messages in thread
From: Chang Wu @ 2026-08-19 15:20 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman
  Cc: Jan Remmet, linux-usb, linux-kernel, Chang Wu, stable

regulator_is_enabled() reports the aggregate regulator state, not
whether this consumer holds an enable reference. If another consumer
enables VBUS first, the driver can skip its own regulator_enable() call
and later attempt to drop a reference it never acquired, triggering an
unbalanced regulator disable warning.

Track successful enable and disable calls locally. Keep the state
unchanged when an operation fails so a later role or ID notification
retries the operation while this consumer keeps balanced references.

Fixes: b3f9d6e491fd ("usb: typec: hd3ss3220: Check if regulator needs to be switched")
Cc: stable@vger.kernel.org
Link: https://github.com/qualcomm-linux/kernel/issues/472
Signed-off-by: Chang Wu <kunjinkao.jp@gmail.com>
---
Testing:
- scripts/checkpatch.pl --strict: passed
- Qualcomm CI checkpatch, sparse, DT and UAPI checks: passed
- Not tested on hardware

 drivers/usb/typec/hd3ss3220.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
index d0de5a2488f9..4eec90c82bae 100644
--- a/drivers/usb/typec/hd3ss3220.c
+++ b/drivers/usb/typec/hd3ss3220.c
@@ -62,6 +62,7 @@ struct hd3ss3220 {
 	int id_irq;
 
 	struct regulator *vbus;
+	bool vbus_enabled;
 };
 
 static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode)
@@ -208,7 +209,7 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
 {
 	int ret;
 
-	if (regulator_is_enabled(hd3ss3220->vbus) == on)
+	if (hd3ss3220->vbus_enabled == on)
 		return;
 
 	if (on)
@@ -216,9 +217,13 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
 	else
 		ret = regulator_disable(hd3ss3220->vbus);
 
-	if (ret)
+	if (ret) {
 		dev_err(hd3ss3220->dev,
 			"vbus regulator %s failed: %d\n", on ? "enable" : "disable", ret);
+		return;
+	}
+
+	hd3ss3220->vbus_enabled = on;
 }
 
 static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)

base-commit: e1e6e541c5c9cf548e9fdc35fc26808c82074440
-- 
2.48.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: hd3ss3220: track VBUS enable state per consumer
  2026-08-19 15:20 [PATCH] usb: typec: hd3ss3220: track VBUS enable state per consumer Chang Wu
@ 2026-08-24 11:20 ` Heikki Krogerus
  2026-08-25 12:39 ` Jan Remmet
  1 sibling, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2026-08-24 11:20 UTC (permalink / raw)
  To: Chang Wu; +Cc: Greg Kroah-Hartman, Jan Remmet, linux-usb, linux-kernel, stable

On Wed, Aug 19, 2026 at 11:20:27PM +0800, Chang Wu wrote:
> regulator_is_enabled() reports the aggregate regulator state, not
> whether this consumer holds an enable reference. If another consumer
> enables VBUS first, the driver can skip its own regulator_enable() call
> and later attempt to drop a reference it never acquired, triggering an
> unbalanced regulator disable warning.
> 
> Track successful enable and disable calls locally. Keep the state
> unchanged when an operation fails so a later role or ID notification
> retries the operation while this consumer keeps balanced references.
> 
> Fixes: b3f9d6e491fd ("usb: typec: hd3ss3220: Check if regulator needs to be switched")
> Cc: stable@vger.kernel.org
> Link: https://github.com/qualcomm-linux/kernel/issues/472
> Signed-off-by: Chang Wu <kunjinkao.jp@gmail.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> Testing:
> - scripts/checkpatch.pl --strict: passed
> - Qualcomm CI checkpatch, sparse, DT and UAPI checks: passed
> - Not tested on hardware
> 
>  drivers/usb/typec/hd3ss3220.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
> index d0de5a2488f9..4eec90c82bae 100644
> --- a/drivers/usb/typec/hd3ss3220.c
> +++ b/drivers/usb/typec/hd3ss3220.c
> @@ -62,6 +62,7 @@ struct hd3ss3220 {
>  	int id_irq;
>  
>  	struct regulator *vbus;
> +	bool vbus_enabled;
>  };
>  
>  static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode)
> @@ -208,7 +209,7 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
>  {
>  	int ret;
>  
> -	if (regulator_is_enabled(hd3ss3220->vbus) == on)
> +	if (hd3ss3220->vbus_enabled == on)
>  		return;
>  
>  	if (on)
> @@ -216,9 +217,13 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
>  	else
>  		ret = regulator_disable(hd3ss3220->vbus);
>  
> -	if (ret)
> +	if (ret) {
>  		dev_err(hd3ss3220->dev,
>  			"vbus regulator %s failed: %d\n", on ? "enable" : "disable", ret);
> +		return;
> +	}
> +
> +	hd3ss3220->vbus_enabled = on;
>  }
>  
>  static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
> 
> base-commit: e1e6e541c5c9cf548e9fdc35fc26808c82074440
> -- 
> 2.48.0

-- 
heikki

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: typec: hd3ss3220: track VBUS enable state per consumer
  2026-08-19 15:20 [PATCH] usb: typec: hd3ss3220: track VBUS enable state per consumer Chang Wu
  2026-08-24 11:20 ` Heikki Krogerus
@ 2026-08-25 12:39 ` Jan Remmet
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Remmet @ 2026-08-25 12:39 UTC (permalink / raw)
  To: Chang Wu, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org

Am 19.08.26 um 17:20 schrieb Chang Wu:
> regulator_is_enabled() reports the aggregate regulator state, not
> whether this consumer holds an enable reference. If another consumer
> enables VBUS first, the driver can skip its own regulator_enable() call
> and later attempt to drop a reference it never acquired, triggering an
> unbalanced regulator disable warning.
> 
> Track successful enable and disable calls locally. Keep the state
> unchanged when an operation fails so a later role or ID notification
> retries the operation while this consumer keeps balanced references.
> 
> Fixes: b3f9d6e491fd ("usb: typec: hd3ss3220: Check if regulator needs to be switched")
> Cc: stable@vger.kernel.org
> Link: https://github.com/qualcomm-linux/kernel/issues/472
> Signed-off-by: Chang Wu <kunjinkao.jp@gmail.com>
tested on our i.MX95 devboard with switching device / host scenarios.

Tested-by: Jan Remmet <j.remmet@phytec.de>
> ---
> Testing:
> - scripts/checkpatch.pl --strict: passed
> - Qualcomm CI checkpatch, sparse, DT and UAPI checks: passed
> - Not tested on hardware
> 
>   drivers/usb/typec/hd3ss3220.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
> index d0de5a2488f9..4eec90c82bae 100644
> --- a/drivers/usb/typec/hd3ss3220.c
> +++ b/drivers/usb/typec/hd3ss3220.c
> @@ -62,6 +62,7 @@ struct hd3ss3220 {
>   	int id_irq;
>   
>   	struct regulator *vbus;
> +	bool vbus_enabled;
>   };
>   
>   static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode)
> @@ -208,7 +209,7 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
>   {
>   	int ret;
>   
> -	if (regulator_is_enabled(hd3ss3220->vbus) == on)
> +	if (hd3ss3220->vbus_enabled == on)
>   		return;
>   
>   	if (on)
> @@ -216,9 +217,13 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
>   	else
>   		ret = regulator_disable(hd3ss3220->vbus);
>   
> -	if (ret)
> +	if (ret) {
>   		dev_err(hd3ss3220->dev,
>   			"vbus regulator %s failed: %d\n", on ? "enable" : "disable", ret);
> +		return;
> +	}
> +
> +	hd3ss3220->vbus_enabled = on;
>   }
>   
>   static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
> 
> base-commit: e1e6e541c5c9cf548e9fdc35fc26808c82074440

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-25 12:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-19 15:20 [PATCH] usb: typec: hd3ss3220: track VBUS enable state per consumer Chang Wu
2026-08-24 11:20 ` Heikki Krogerus
2026-08-25 12:39 ` Jan Remmet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox