mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] counter: ti-eqep: balance pm_runtime on devm_clk_get_enabled() failure
@ 2026-05-23 18:44 Stepan Ionichev
  2026-05-23 18:59 ` Maxwell Doose
  0 siblings, 1 reply; 2+ messages in thread
From: Stepan Ionichev @ 2026-05-23 18:44 UTC (permalink / raw)
  To: wbg; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, sozdayvek

ti_eqep_probe() calls pm_runtime_enable() and pm_runtime_get_sync()
before devm_clk_get_enabled(). If the clk call fails, the function
returns directly via dev_err_probe(), leaving runtime PM enabled
and the usage counter incremented.

Route the clk error through the same err_pm cleanup as counter_add()
so the runtime PM state is unwound on every failure path.

Signed-off-by: Stepan Ionichev <sozdayvek@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 d21c157e5..6b79a50fd 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 = PTR_ERR(clk);
+		dev_err_probe(dev, err, "failed to enable clock\n");
+		goto err_pm;
+	}
 
 	err = counter_add(counter);
-	if (err < 0) {
-		pm_runtime_put_sync(dev);
-		pm_runtime_disable(dev);
-		return err;
-	}
+	if (err < 0)
+		goto err_pm;
 
 	return 0;
+
+err_pm:
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
+	return err;
 }
 
 static void ti_eqep_remove(struct platform_device *pdev)
-- 
2.43.0


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

* Re: [PATCH] counter: ti-eqep: balance pm_runtime on devm_clk_get_enabled() failure
  2026-05-23 18:44 [PATCH] counter: ti-eqep: balance pm_runtime on devm_clk_get_enabled() failure Stepan Ionichev
@ 2026-05-23 18:59 ` Maxwell Doose
  0 siblings, 0 replies; 2+ messages in thread
From: Maxwell Doose @ 2026-05-23 18:59 UTC (permalink / raw)
  To: Stepan Ionichev; +Cc: wbg, dlechner, nuno.sa, andy, linux-iio, linux-kernel

On Sat, May 23, 2026 at 1:45 PM Stepan Ionichev <sozdayvek@gmail.com> wrote:
>
> ti_eqep_probe() calls pm_runtime_enable() and pm_runtime_get_sync()
> before devm_clk_get_enabled(). If the clk call fails, the function
> returns directly via dev_err_probe(), leaving runtime PM enabled
> and the usage counter incremented.
>
> Route the clk error through the same err_pm cleanup as counter_add()
> so the runtime PM state is unwound on every failure path.
>
> Signed-off-by: Stepan Ionichev <sozdayvek@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 d21c157e5..6b79a50fd 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 = PTR_ERR(clk);
> +               dev_err_probe(dev, err, "failed to enable clock\n");
> +               goto err_pm;
> +       }
>

I'm curious, why not something like (and not compiled):

err = dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
goto err_pm;

Since (I'm pretty sure that) dev_err_probe() also returns argument 2
(which is the error that we pass in, which in this snippet is
PTR_ERR(clk)).

best regards,
max

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

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

end of thread, other threads:[~2026-05-23 19:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-23 18:44 [PATCH] counter: ti-eqep: balance pm_runtime on devm_clk_get_enabled() failure Stepan Ionichev
2026-05-23 18:59 ` Maxwell Doose

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

all inboxes | Powered by JetHome®