Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: phy: twl6030-usb: disable usb3v3 before releasing it
@ 2026-11-19  8:15 Wang Haoran
  2026-11-19  8:29 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Haoran @ 2026-11-19  8:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, linux-kernel, wanghr2026

The VBUS and ID interrupt handlers enable usb3v3 and track the state in
twl->asleep, but the remove path only calls regulator_put(), which warns on
the still-held enable count and leaves the LDO powered until the PMIC
itself powers down. Unbinding with an ID-grounded cable therefore leaves
the USB PHY rail enabled and pollutes dmesg with the enable_count WARN on
every unbind.

Disable usb3v3 in remove and in the probe error path when it was left
enabled, guarded by the existing asleep state.

Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: c33fad0c3748 ("usb: otg: Adding twl6030-usb transceiver driver for OMAP4430")
---

diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index 9bfcb2c1dfd0..6a53417ecad4 100644
--- a/drivers/usb/phy/phy-twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -403,6 +403,8 @@ static int twl6030_usb_probe(struct platform_device *pdev)
 err_free_irq1:
 	free_irq(twl->irq1, twl);
 err_put_regulator:
+	if (twl->asleep)
+		regulator_disable(twl->usb3v3);
 	regulator_put(twl->usb3v3);
 
 	return status;
@@ -419,6 +421,8 @@ static void twl6030_usb_remove(struct platform_device *pdev)
 			REG_INT_MSK_STS_C);
 	free_irq(twl->irq1, twl);
 	free_irq(twl->irq2, twl);
+	if (twl->asleep)
+		regulator_disable(twl->usb3v3);
 	regulator_put(twl->usb3v3);
 	cancel_work_sync(&twl->set_vbus_work);
 }

---

The vulnerability was found by static analysis.


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

* Re: [PATCH] usb: phy: twl6030-usb: disable usb3v3 before releasing it
  2026-11-19  8:15 [PATCH] usb: phy: twl6030-usb: disable usb3v3 before releasing it Wang Haoran
@ 2026-11-19  8:29 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19  8:29 UTC (permalink / raw)
  To: Wang Haoran; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: phy: twl6030-usb: unbalanced regulator_enable() and
  boolean asleep state
--

commit b6e0cbcd5a82c4c16825ea0e177dbacfb07f951d
Author: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>

usb: phy: twl6030-usb: disable usb3v3 before releasing it

This commit disables the usb3v3 regulator in twl6030_usb_remove() and the
twl6030_usb_probe() error path when twl->asleep is non-zero before calling
regulator_put().

> diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
> index 9bfcb2c1dfd0e..6a53417ecad4f 100644
> --- a/drivers/usb/phy/phy-twl6030-usb.c
> +++ b/drivers/usb/phy/phy-twl6030-usb.c
> @@ -403,6 +403,8 @@ static int twl6030_usb_probe(struct platform_device *pdev)
>  err_free_irq1:
>  	free_irq(twl->irq1, twl);
>  err_put_regulator:
> +	if (twl->asleep)
> +		regulator_disable(twl->usb3v3);
>  	regulator_put(twl->usb3v3);
>  
>  	return status;
> @@ -419,6 +421,8 @@ static void twl6030_usb_remove(struct platform_device *pdev)
>  			REG_INT_MSK_STS_C);
>  	free_irq(twl->irq1, twl);
>  	free_irq(twl->irq2, twl);
> +	if (twl->asleep)
> +		regulator_disable(twl->usb3v3);
>  	regulator_put(twl->usb3v3);
>  	cancel_work_sync(&twl->set_vbus_work);
>  }

[Severity: Medium]
Can a single regulator_disable(twl->usb3v3) guarded by the boolean
twl->asleep still leave twl->usb3v3 unbalanced on teardown?

Both twl6030_usb_irq() and twl6030_usbotg_irq() call
regulator_enable(twl->usb3v3) without checking !twl->asleep, and set
twl->asleep = 1 even when regulator_enable() fails:

drivers/usb/phy/phy-twl6030-usb.c:twl6030_usbotg_irq() {
    ...
	if (hw_state & STS_USB_ID) {
		ret = regulator_enable(twl->usb3v3);
		if (ret)
			dev_err(twl->dev, "Failed to enable usb3v3\n");

		twl->asleep = 1;
    ...
}

Because twl6030_usb_probe() enables the PMIC interrupts and also schedules
twl6030_status_work() to invoke both IRQ handlers 1 HZ later (and
twl6030_usbotg_irq() never disables usb3v3 when STS_USB_ID clears), any
ID-ground or VBUS interrupt firing before twl6030_status_work() runs
increments enable_count to 2 or more while twl->asleep stays 1, so the
single regulator_disable() in twl6030_usb_remove() still triggers
WARN_ON(regulator->enable_count) in _regulator_put() and leaves the rail
enabled. Conversely, if regulator_enable() fails, twl->asleep is still set
to 1, causing the new regulator_disable() on teardown to warn on an
unbalanced disable.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/1795076108884-14-6a4060a6@mail.zgclab.edu.cn?part=1

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

end of thread, other threads:[~2026-11-19  8:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  8:15 [PATCH] usb: phy: twl6030-usb: disable usb3v3 before releasing it Wang Haoran
2026-11-19  8:29 ` sashiko-bot

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