[PATCH] counter: ti-eqep: fix runtime PM leak in probe error path

Felix Gu posted 1 patch 1 month, 4 weeks ago
There is a newer version of this series
drivers/counter/ti-eqep.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
[PATCH] counter: ti-eqep: fix runtime PM leak in probe error path
Posted by Felix Gu 1 month, 4 weeks ago
In ti_eqep_probe(), if devm_clk_get_enabled() fails, the function
returns without cleaning up the runtime PM state.

Fixes: 0cf81c73e4c6 ("counter: ti-eqep: enable clock at probe")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/counter/ti-eqep.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
index d21c157e531a..dfa945b3eec6 100644
--- a/drivers/counter/ti-eqep.c
+++ b/drivers/counter/ti-eqep.c
@@ -548,17 +548,22 @@ static int ti_eqep_probe(struct platform_device *pdev)
 	pm_runtime_get_sync(dev);
 
 	clk = devm_clk_get_enabled(dev, NULL);
-	if (IS_ERR(clk))
-		return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
+	if (IS_ERR(clk)) {
+		err = dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
+		goto disable_pm;
+	}
 
 	err = counter_add(counter);
-	if (err < 0) {
-		pm_runtime_put_sync(dev);
-		pm_runtime_disable(dev);
-		return err;
-	}
+	if (err < 0)
+		goto disable_pm;
 
 	return 0;
+
+disable_pm:
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
+
+	return err;
 }
 
 static void ti_eqep_remove(struct platform_device *pdev)

---
base-commit: 452c3b1ea875276105ac90ba474f72b4cd9b77a2
change-id: 20260417-ti-eqep-8efb9cc713ea

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>
Re: [PATCH] counter: ti-eqep: fix runtime PM leak in probe error path
Posted by David Lechner 1 month, 4 weeks ago
My knowledge of pm_runtime is a bit lacking, so I would suggest
to include that mailing list on the CC to get more expert review.


On 4/17/26 10:06 AM, Felix Gu wrote:
> In ti_eqep_probe(), if devm_clk_get_enabled() fails, the function
> returns without cleaning up the runtime PM state.
> 
> Fixes: 0cf81c73e4c6 ("counter: ti-eqep: enable clock at probe")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>  drivers/counter/ti-eqep.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
> index d21c157e531a..dfa945b3eec6 100644
> --- a/drivers/counter/ti-eqep.c
> +++ b/drivers/counter/ti-eqep.c
> @@ -548,17 +548,22 @@ static int ti_eqep_probe(struct platform_device *pdev)

Can we use devm_pm_runtime_enable() to partially solve this?

>  	pm_runtime_get_sync(dev);

I don't think we should have non-devm stuff before devm stuff
so this needs to be moved later of have some kind of devm cleanup.

>  
>  	clk = devm_clk_get_enabled(dev, NULL);
> -	if (IS_ERR(clk))
> -		return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
> +	if (IS_ERR(clk)) {
> +		err = dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
> +		goto disable_pm;
> +	}
>  
>  	err = counter_add(counter);

This can be changed to devm_counter_add().

> -	if (err < 0) {
> -		pm_runtime_put_sync(dev);
> -		pm_runtime_disable(dev);
> -		return err;
> -	}
> +	if (err < 0)
> +		goto disable_pm;
>  
>  	return 0;
> +
> +disable_pm:
> +	pm_runtime_put_sync(dev);
> +	pm_runtime_disable(dev);
> +
> +	return err;
>  }
>  
>  static void ti_eqep_remove(struct platform_device *pdev)

And once everything is converted to devm, we can drop the
remove callback.

> 
> ---
> base-commit: 452c3b1ea875276105ac90ba474f72b4cd9b77a2
> change-id: 20260417-ti-eqep-8efb9cc713ea
> 
> Best regards,