From: sashiko-bot@kernel.org
To: "Wang Haoran" <wanghr2026@mail.zgclab.edu.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: phy: twl6030-usb: disable usb3v3 before releasing it
Date: Thu, 19 Nov 2026 08:29:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-222670@kernel.org> (raw)
In-Reply-To: <1795076108884-14-6a4060a6@mail.zgclab.edu.cn>
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
prev parent reply other threads:[~2026-11-19 8:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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-222670@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wanghr2026@mail.zgclab.edu.cn \
/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.