Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: meson: g12a: disable vbus on removal
@ 2026-11-19  8:15 Wang Haoran
  2026-11-19  8:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Haoran @ 2026-11-19  8:15 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, neil.armstrong, khilman
  Cc: jbrunet, martin.blumenstingl, linux-usb, linux-arm-kernel,
	linux-amlogic, linux-kernel, wanghr2026

dwc3_meson_g12a_probe() enables the vbus regulator, but the remove path
neither disables it nor runs the suspend callback (pm_runtime_disable +
pm_runtime_set_suspended short-circuits it), so VBUS stays powered after
the driver is detached. The probe error path already unwinds the regulator,
so this is simply the missing remove-side counterpart: the USB port keeps
supplying 5V to an attached device even after the glue driver is unbound.

Disable vbus in the remove path to match probe.

Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: c99993376f72 ("usb: dwc3: Add Amlogic G12A DWC3 glue")
---

diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c
index ca07e813fd64..4d68b50722e7 100644
--- a/drivers/usb/dwc3/dwc3-meson-g12a.c
+++ b/drivers/usb/dwc3/dwc3-meson-g12a.c
@@ -847,6 +847,9 @@ static void dwc3_meson_g12a_remove(struct platform_device *pdev)
 		phy_exit(priv->phys[i]);
 	}
 
+	if (priv->vbus)
+		regulator_disable(priv->vbus);
+
 	pm_runtime_disable(dev);
 	pm_runtime_put_noidle(dev);
 	pm_runtime_set_suspended(dev);

---

The vulnerability was found by static analysis.


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

* Re: [PATCH] usb: dwc3: meson: g12a: disable vbus on removal
  2026-11-19  8:15 [PATCH] usb: dwc3: meson: g12a: disable vbus on removal Wang Haoran
@ 2026-11-19  8:26 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19  8:26 UTC (permalink / raw)
  To: Wang Haoran; +Cc: linux-usb, linux-amlogic, neil.armstrong

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: dwc3: meson-g12a: unbalanced vbus disable in
  dwc3_meson_g12a_remove()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] usb: dwc3: meson-g12a: unclocked access in
  dwc3_meson_g12a_irq_thread() [1]
--

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

usb: dwc3: meson: g12a: disable vbus on removal

This commit disables the vbus regulator in dwc3_meson_g12a_remove() to
balance the regulator_enable() call in dwc3_meson_g12a_probe().

> diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c
> index ca07e813fd64f..4d68b50722e76 100644
> --- a/drivers/usb/dwc3/dwc3-meson-g12a.c
> +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c
> @@ -847,6 +847,9 @@ static void dwc3_meson_g12a_remove(struct platform_device *pdev)
>  		phy_exit(priv->phys[i]);
>  	}
>  
> +	if (priv->vbus)
> +		regulator_disable(priv->vbus);

[Severity: Medium]
Can this cause an unbalanced regulator_disable() on priv->vbus when the
controller is removed while in device mode?

When dwc3_meson_g12a_otg_mode_set() switches to PHY_MODE_USB_DEVICE, it
already disables priv->vbus:

drivers/usb/dwc3/dwc3-meson-g12a.c:dwc3_meson_g12a_otg_mode_set() {
    ...
	if (priv->vbus) {
		if (mode == PHY_MODE_USB_DEVICE)
			ret = regulator_disable(priv->vbus);
		else
			ret = regulator_enable(priv->vbus);
		if (ret)
			return ret;
	}

	priv->otg_phy_mode = mode;
    ...
}

Should this check priv->otg_phy_mode == PHY_MODE_USB_HOST before calling
regulator_disable(priv->vbus), matching dwc3_meson_g12a_suspend()?

> +
>  	pm_runtime_disable(dev);
>  	pm_runtime_put_noidle(dev);
>  	pm_runtime_set_suspended(dev);

[Severity: High]
This problem wasn't introduced by this patch, but can
dwc3_meson_g12a_irq_thread() read unclocked registers during driver removal
[1]?

The OTG interrupt is requested via devm_request_threaded_irq(), so it stays
enabled until devres cleanup runs after dwc3_meson_g12a_remove() returns,
while dwc3_meson_g12a_remove() disables the clocks via
clk_bulk_disable_unprepare() before returning:

CPU0                                CPU1
dwc3_meson_g12a_remove()
  ...
  clk_bulk_disable_unprepare()
                                    dwc3_meson_g12a_irq_thread()
                                      dwc3_meson_g12a_get_id()
                                        regmap_read(priv->usb_glue_regmap, ...)
                                          <-- unclocked register access
devres_release_all()

If an OTG interrupt fires in that window, reading priv->usb_glue_regmap with
the clocks disabled triggers an asynchronous external abort.

[1] https://sashiko.dev/#/bug/linux-901d8f75-b80e-43d7-b50d-1dc1755ce4f5

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/1795076109480-15-f562c8e5@mail.zgclab.edu.cn?part=1

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

end of thread, other threads:[~2026-11-19  8:26 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: dwc3: meson: g12a: disable vbus on removal Wang Haoran
2026-11-19  8:26 ` sashiko-bot

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