* [PATCH] phy: fsl-imx8mq-usb: fix vbus regulator leak on error paths
@ 2026-06-02 13:14 Felix Gu
2026-06-02 13:22 ` Frank Li
2026-06-03 5:39 ` Xu Yang
0 siblings, 2 replies; 3+ messages in thread
From: Felix Gu @ 2026-06-02 13:14 UTC (permalink / raw)
To: Vinod Koul, Neil Armstrong, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Xu Yang
Cc: linux-phy, imx, linux-arm-kernel, linux-kernel, Felix Gu
In imx8mq_phy_power_on(), if clk_prepare_enable() fails after
regulator_enable() has succeeded, the vbus regulator is left
enabled. The same issue exists for the alt_clk error path.
Fix both by converting to the standard goto-based cleanup
pattern, ensuring the regulator is disabled when any
subsequent step fails.
Fixes: 3b64ea4768e7 ("phy: fsl-imx8mq-usb: support alternate reference clock")
Signed-off-by: Felix Gu <ustc.gu@gmail•com>
---
drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
index b05d80e849a1..e45e4f16057e 100644
--- a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
+++ b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
@@ -627,13 +627,11 @@ static int imx8mq_phy_power_on(struct phy *phy)
ret = clk_prepare_enable(imx_phy->clk);
if (ret)
- return ret;
+ goto disable_vbus;
ret = clk_prepare_enable(imx_phy->alt_clk);
- if (ret) {
- clk_disable_unprepare(imx_phy->clk);
- return ret;
- }
+ if (ret)
+ goto disable_clk;
/* Disable rx term override */
value = readl(imx_phy->base + PHY_CTRL6);
@@ -641,6 +639,13 @@ static int imx8mq_phy_power_on(struct phy *phy)
writel(value, imx_phy->base + PHY_CTRL6);
return 0;
+
+disable_clk:
+ clk_disable_unprepare(imx_phy->clk);
+disable_vbus:
+ regulator_disable(imx_phy->vbus);
+
+ return ret;
}
static int imx8mq_phy_power_off(struct phy *phy)
---
base-commit: 08484c504b55a98bd100527fbe10a3caf55ff3ff
change-id: 20260602-imx9mq-30169239b590
Best regards,
--
Felix Gu <ustc.gu@gmail•com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] phy: fsl-imx8mq-usb: fix vbus regulator leak on error paths
2026-06-02 13:14 [PATCH] phy: fsl-imx8mq-usb: fix vbus regulator leak on error paths Felix Gu
@ 2026-06-02 13:22 ` Frank Li
2026-06-03 5:39 ` Xu Yang
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-06-02 13:22 UTC (permalink / raw)
To: Felix Gu
Cc: Vinod Koul, Neil Armstrong, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Xu Yang, linux-phy, imx, linux-arm-kernel,
linux-kernel
On Tue, Jun 02, 2026 at 09:14:33PM +0800, Felix Gu wrote:
> In imx8mq_phy_power_on(), if clk_prepare_enable() fails after
> regulator_enable() has succeeded, the vbus regulator is left
> enabled. The same issue exists for the alt_clk error path.
>
> Fix both by converting to the standard goto-based cleanup
> pattern, ensuring the regulator is disabled when any
> subsequent step fails.
>
> Fixes: 3b64ea4768e7 ("phy: fsl-imx8mq-usb: support alternate reference clock")
> Signed-off-by: Felix Gu <ustc.gu@gmail•com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp•com>
> drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
> index b05d80e849a1..e45e4f16057e 100644
> --- a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
> +++ b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
> @@ -627,13 +627,11 @@ static int imx8mq_phy_power_on(struct phy *phy)
>
> ret = clk_prepare_enable(imx_phy->clk);
> if (ret)
> - return ret;
> + goto disable_vbus;
>
> ret = clk_prepare_enable(imx_phy->alt_clk);
> - if (ret) {
> - clk_disable_unprepare(imx_phy->clk);
> - return ret;
> - }
> + if (ret)
> + goto disable_clk;
>
> /* Disable rx term override */
> value = readl(imx_phy->base + PHY_CTRL6);
> @@ -641,6 +639,13 @@ static int imx8mq_phy_power_on(struct phy *phy)
> writel(value, imx_phy->base + PHY_CTRL6);
>
> return 0;
> +
> +disable_clk:
> + clk_disable_unprepare(imx_phy->clk);
> +disable_vbus:
> + regulator_disable(imx_phy->vbus);
> +
> + return ret;
> }
>
> static int imx8mq_phy_power_off(struct phy *phy)
>
> ---
> base-commit: 08484c504b55a98bd100527fbe10a3caf55ff3ff
> change-id: 20260602-imx9mq-30169239b590
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail•com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] phy: fsl-imx8mq-usb: fix vbus regulator leak on error paths
2026-06-02 13:14 [PATCH] phy: fsl-imx8mq-usb: fix vbus regulator leak on error paths Felix Gu
2026-06-02 13:22 ` Frank Li
@ 2026-06-03 5:39 ` Xu Yang
1 sibling, 0 replies; 3+ messages in thread
From: Xu Yang @ 2026-06-03 5:39 UTC (permalink / raw)
To: Felix Gu
Cc: Vinod Koul, Neil Armstrong, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Xu Yang, linux-phy, imx,
linux-arm-kernel, linux-kernel
Hi Felix,
On Tue, Jun 02, 2026 at 09:14:33PM +0800, Felix Gu wrote:
> In imx8mq_phy_power_on(), if clk_prepare_enable() fails after
> regulator_enable() has succeeded, the vbus regulator is left
> enabled. The same issue exists for the alt_clk error path.
>
> Fix both by converting to the standard goto-based cleanup
> pattern, ensuring the regulator is disabled when any
> subsequent step fails.
I am fixing the bugs which are reported by sashiko-bot based on my previous
patch these days. And I already build a patchset to add runtime PM support
which will move all clock callbakcs to runtime operations. Therefore, this
patch is not needed anymore once runtime PM is ready.
Please refer to:
https://lore.kernel.org/linux-phy/20260603-imx8mp-usb-phy-improvement-v3-0-7afb8f89abc6@nxp.com/T/#t
Thanks,
Xu Yang
>
> Fixes: 3b64ea4768e7 ("phy: fsl-imx8mq-usb: support alternate reference clock")
> Signed-off-by: Felix Gu <ustc.gu@gmail•com>
> ---
> drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
> index b05d80e849a1..e45e4f16057e 100644
> --- a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
> +++ b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
> @@ -627,13 +627,11 @@ static int imx8mq_phy_power_on(struct phy *phy)
>
> ret = clk_prepare_enable(imx_phy->clk);
> if (ret)
> - return ret;
> + goto disable_vbus;
>
> ret = clk_prepare_enable(imx_phy->alt_clk);
> - if (ret) {
> - clk_disable_unprepare(imx_phy->clk);
> - return ret;
> - }
> + if (ret)
> + goto disable_clk;
>
> /* Disable rx term override */
> value = readl(imx_phy->base + PHY_CTRL6);
> @@ -641,6 +639,13 @@ static int imx8mq_phy_power_on(struct phy *phy)
> writel(value, imx_phy->base + PHY_CTRL6);
>
> return 0;
> +
> +disable_clk:
> + clk_disable_unprepare(imx_phy->clk);
> +disable_vbus:
> + regulator_disable(imx_phy->vbus);
> +
> + return ret;
> }
>
> static int imx8mq_phy_power_off(struct phy *phy)
>
> ---
> base-commit: 08484c504b55a98bd100527fbe10a3caf55ff3ff
> change-id: 20260602-imx9mq-30169239b590
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail•com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-03 5:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 13:14 [PATCH] phy: fsl-imx8mq-usb: fix vbus regulator leak on error paths Felix Gu
2026-06-02 13:22 ` Frank Li
2026-06-03 5:39 ` Xu Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox