Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH] clk: imx: scu: fix autosuspend cleanup on probe failure
@ 2026-08-08  8:29 Guangshuo Li
  2026-08-08  8:47 ` sashiko-bot
  2026-08-10 13:03 ` Peng Fan
  0 siblings, 2 replies; 3+ messages in thread
From: Guangshuo Li @ 2026-08-08  8:29 UTC (permalink / raw)
  To: Abel Vesa, Peng Fan, Michael Turquette, Stephen Boyd,
	Brian Masney, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, Dong Aisheng, Shawn Guo, linux-clk, imx,
	linux-arm-kernel, linux-kernel
  Cc: Guangshuo Li, stable

imx_clk_scu_probe() calls pm_runtime_use_autosuspend() for non-CPU
clocks, but its probe failure paths do not call the matching
pm_runtime_dont_use_autosuspend() before disabling runtime PM.

If the autosuspend delay is set to a negative value while autosuspend
is enabled, the runtime PM core increments usage_count to prevent
runtime suspend. Without calling pm_runtime_dont_use_autosuspend()
during cleanup, this reference is not dropped and usage_count remains
unbalanced.

Add the missing pm_runtime_dont_use_autosuspend() calls to the probe
failure paths before disabling runtime PM.

This issue was found by manual code inspection.

Fixes: 78edeb080330 ("clk: imx: scu: add runtime pm support")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/clk/imx/clk-scu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
index 9b33df9967ec..6d29fcc2306d 100644
--- a/drivers/clk/imx/clk-scu.c
+++ b/drivers/clk/imx/clk-scu.c
@@ -542,6 +542,7 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
 		ret = pm_runtime_resume_and_get(dev);
 		if (ret) {
 			pm_genpd_remove_device(dev);
+			pm_runtime_dont_use_autosuspend(dev);
 			pm_runtime_disable(dev);
 			return ret;
 		}
@@ -550,6 +551,9 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
 	hw = __imx_clk_scu(dev, clk->name, clk->parents, clk->num_parents,
 			   clk->rsrc, clk->clk_type);
 	if (IS_ERR(hw)) {
+		if (!(clk->rsrc == IMX_SC_R_A35 || clk->rsrc == IMX_SC_R_A53 ||
+		      clk->rsrc == IMX_SC_R_A72))
+			pm_runtime_dont_use_autosuspend(dev);
 		pm_runtime_disable(dev);
 		return PTR_ERR(hw);
 	}
-- 
2.43.0


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

* Re: [PATCH] clk: imx: scu: fix autosuspend cleanup on probe failure
  2026-08-08  8:29 [PATCH] clk: imx: scu: fix autosuspend cleanup on probe failure Guangshuo Li
@ 2026-08-08  8:47 ` sashiko-bot
  2026-08-10 13:03 ` Peng Fan
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-08-08  8:47 UTC (permalink / raw)
  To: Guangshuo Li; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Incomplete error path cleanup: usage counter leak and unbalanced runtime PM disable
--

--- Patch [1]: [PATCH] clk: imx: scu: fix autosuspend cleanup on probe failure ---
commit be1da3e608e79b11e6b956430089bc533d7bfdbd
Author: Guangshuo Li <lgs201920130244@gmail.com>

clk: imx: scu: fix autosuspend cleanup on probe failure

This commit adds missing calls to pm_runtime_dont_use_autosuspend in the
probe failure paths of the imx-scu clock driver. This prevents an unbalanced
usage counter when the autosuspend delay is set to a negative value.

> diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
> index 9b33df9967ece..6d29fcc2306d8 100644
> --- a/drivers/clk/imx/clk-scu.c
> +++ b/drivers/clk/imx/clk-scu.c

[ ... ]

> @@ -542,6 +542,7 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
>  		ret = pm_runtime_resume_and_get(dev);
>  		if (ret) {
>  			pm_genpd_remove_device(dev);
> +			pm_runtime_dont_use_autosuspend(dev);
>  			pm_runtime_disable(dev);
>  			return ret;
>  		}
> @@ -550,6 +551,9 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
>  	hw = __imx_clk_scu(dev, clk->name, clk->parents, clk->num_parents,
>  			   clk->rsrc, clk->clk_type);
>  	if (IS_ERR(hw)) {
> +		if (!(clk->rsrc == IMX_SC_R_A35 || clk->rsrc == IMX_SC_R_A53 ||
> +		      clk->rsrc == IMX_SC_R_A72))
> +			pm_runtime_dont_use_autosuspend(dev);
>  		pm_runtime_disable(dev);
>  		return PTR_ERR(hw);
>  	}

[Severity: High]
This isn't a bug introduced by this patch, but since this modifies the error
path, is there a missing call to pm_runtime_put_noidle here?

Earlier in imx_clk_scu_probe, for non-CPU clocks, pm_runtime_resume_and_get
is called and increments the usage counter on success. If __imx_clk_scu
subsequently fails, it appears the usage count is leaked, which would
prevent the device and its power domain from ever suspending.

Also, pm_runtime_disable is called unconditionally here, but
pm_runtime_enable was only called if the clock was a non-CPU clock. Does
this cause an unbalanced runtime PM disable depth for CPU clocks?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260808082933.2692878-1-lgs201920130244@gmail.com?part=1

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

* Re: [PATCH] clk: imx: scu: fix autosuspend cleanup on probe failure
  2026-08-08  8:29 [PATCH] clk: imx: scu: fix autosuspend cleanup on probe failure Guangshuo Li
  2026-08-08  8:47 ` sashiko-bot
@ 2026-08-10 13:03 ` Peng Fan
  1 sibling, 0 replies; 3+ messages in thread
From: Peng Fan @ 2026-08-10 13:03 UTC (permalink / raw)
  To: Guangshuo Li
  Cc: Abel Vesa, Peng Fan, Michael Turquette, Stephen Boyd,
	Brian Masney, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, Dong Aisheng, Shawn Guo, linux-clk, imx,
	linux-arm-kernel, linux-kernel, stable

Hi,

On Sat, Aug 08, 2026 at 04:29:33PM +0800, Guangshuo Li wrote:
>imx_clk_scu_probe() calls pm_runtime_use_autosuspend() for non-CPU
>clocks, but its probe failure paths do not call the matching
>pm_runtime_dont_use_autosuspend() before disabling runtime PM.
>
>If the autosuspend delay is set to a negative value while autosuspend
>is enabled, the runtime PM core increments usage_count to prevent
>runtime suspend. Without calling pm_runtime_dont_use_autosuspend()
>during cleanup, this reference is not dropped and usage_count remains
>unbalanced.
>
>Add the missing pm_runtime_dont_use_autosuspend() calls to the probe
>failure paths before disabling runtime PM.
>
>This issue was found by manual code inspection.
>
>Fixes: 78edeb080330 ("clk: imx: scu: add runtime pm support")
>Cc: stable@vger.kernel.org
>Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
>---
> drivers/clk/imx/clk-scu.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
>diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
>index 9b33df9967ec..6d29fcc2306d 100644
>--- a/drivers/clk/imx/clk-scu.c
>+++ b/drivers/clk/imx/clk-scu.c
>@@ -542,6 +542,7 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
> 		ret = pm_runtime_resume_and_get(dev);
> 		if (ret) {
> 			pm_genpd_remove_device(dev);
>+			pm_runtime_dont_use_autosuspend(dev);
> 			pm_runtime_disable(dev);
> 			return ret;
> 		}
>@@ -550,6 +551,9 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
> 	hw = __imx_clk_scu(dev, clk->name, clk->parents, clk->num_parents,
> 			   clk->rsrc, clk->clk_type);
> 	if (IS_ERR(hw)) {
>+		if (!(clk->rsrc == IMX_SC_R_A35 || clk->rsrc == IMX_SC_R_A53 ||
>+		      clk->rsrc == IMX_SC_R_A72))
>+			pm_runtime_dont_use_autosuspend(dev);
> 		pm_runtime_disable(dev);
> 		return PTR_ERR(hw);

This is not complete fix. I just write one, see below:

imx_clk_scu_probe() sets up runtime PM for non-CPU clocks by calling
pm_runtime_use_autosuspend(), pm_runtime_enable(), and
pm_runtime_resume_and_get(). The probe failure paths do not properly
undo these operations:

1. When pm_runtime_resume_and_get() fails, pm_runtime_dont_use_autosuspend()
   is not called before pm_runtime_disable(), leaving the autosuspend
   setting unbalanced.

2. When __imx_clk_scu() fails, pm_runtime_disable() is called
   unconditionally even for CPU clocks, which never had pm_runtime_enable()
   called, causing an unbalanced disable depth. For non-CPU clocks,
   neither pm_runtime_put_noidle() nor pm_runtime_dont_use_autosuspend()
   are called, leaving both the usage count and autosuspend setting
   unbalanced.

Fix the first path by adding pm_runtime_dont_use_autosuspend() before
pm_runtime_disable(). Fix the second path by guarding all three cleanup
calls — pm_runtime_put_noidle(), pm_runtime_dont_use_autosuspend(), and
pm_runtime_disable() — with the non-CPU clock check.

Fixes: 78edeb080330 ("clk: imx: scu: add runtime pm support")
Signed-off-by: Peng Fan <peng.fan@nxp.com>

diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
index 9b33df9967ece..63ab4801ddaa7 100644
--- a/drivers/clk/imx/clk-scu.c
+++ b/drivers/clk/imx/clk-scu.c
@@ -542,6 +542,7 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
                ret = pm_runtime_resume_and_get(dev);
                if (ret) {
                        pm_genpd_remove_device(dev);
+                       pm_runtime_dont_use_autosuspend(dev);
                        pm_runtime_disable(dev);
                        return ret;
                }
@@ -550,7 +551,12 @@ static int imx_clk_scu_probe(struct platform_device *pdev)
        hw = __imx_clk_scu(dev, clk->name, clk->parents, clk->num_parents,
                           clk->rsrc, clk->clk_type);
        if (IS_ERR(hw)) {
-               pm_runtime_disable(dev);
+               if (!((clk->rsrc == IMX_SC_R_A35) || (clk->rsrc == IMX_SC_R_A53) ||
+                   (clk->rsrc == IMX_SC_R_A72))) {
+                       pm_runtime_put_noidle(dev);
+                       pm_runtime_dont_use_autosuspend(dev);
+                       pm_runtime_disable(dev);
+               }
                return PTR_ERR(hw);
        }


Regards,
Peng

> 	}
>-- 
>2.43.0
>

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-08  8:29 [PATCH] clk: imx: scu: fix autosuspend cleanup on probe failure Guangshuo Li
2026-08-08  8:47 ` sashiko-bot
2026-08-10 13:03 ` Peng Fan

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