Skip to contentSkip to conversation

counter: ti-eqep: balance pm_runtime on devm_clk_get_enabled() failure

PATCH Applied Stepan Ionichev 4 participants 7 messages May 25 – May 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 counter: ti-eqep: balance pm_runtime on devm_clk_get_enabled() failure

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.

Fixes f213729f6796 ("counter: new TI eQEP driver")

---
v2:
- Collapse the dev_err_probe()+assignment pair into a single line using its return value (Maxwell)
- Add Fixes tag

v1: https://lore.kernel.org/all/[email protected]/

 drivers/counter/ti-eqep.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/counter/ti-eqep.c +11 -7
index d21c157e5..4f3b17939 100644
@@ -548,17 +548,21 @@ 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 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)
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 56 lines · Stepan Ionichev

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.

Fixes f213729f6796 ("counter: new TI eQEP driver")

---
v2:
- Collapse the dev_err_probe()+assignment pair into a single line using its return value (Maxwell)
- Add Fixes tag

v1: https://lore.kernel.org/all/[email protected]/

 drivers/counter/ti-eqep.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/counter/ti-eqep.c +11 -8
index d21c157e5..4f3b17939 100644
@@ -548,17 +548,21 @@ 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 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)
--
Quoted 2 lines

2.43.0

Sashiko came back with some notes, however they are issues unrelated to this patch. LGTM.

Signature · 3 lines
Kind regards

CJD
maintainer Applied
#2 lore raw
In reply to Stepan Ionichev
Quoted 9 lines · Stepan Ionichev

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.

[...]

Applied, thanks!

[1/1] counter: ti-eqep: balance pm_runtime on devm_clk_get_enabled() failure

      commit: abeabb5fc6a7d4c347d494dfe5bc9449c4535226

Best regards,

Signature · 1 line
William Breathitt Gray <[email protected]>
#3 lore raw
In reply to Stepan Ionichev
Quoted 8 lines · Stepan Ionichev

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.

...

drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 553

Quoted 8 lines
        pm_runtime_get_sync(dev);

        clk = devm_clk_get_enabled(dev, NULL);
drivers/counter/ti-eqep.c +3 -2
-       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 err_pm;

This is not right. The devm_*() should not be followed by goto.

Quoted 1 line

+ }

...

drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 565

Quoted 4 lines
drivers/counter/ti-eqep.c +4 -0
+err_pm:
+       pm_runtime_put_sync(dev);
+       pm_runtime_disable(dev);
+       return err;

You have to use the respective devm_pm_*() at the same time.

...

William, this patch should not be applied (or should be reverted) as in current form it replaces one issue by another.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 34 lines · Andy Shevchenko
Quoted 8 lines · Stepan Ionichev

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.

...

drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 553

Quoted 8 lines
        pm_runtime_get_sync(dev);

        clk = devm_clk_get_enabled(dev, NULL);
drivers/counter/ti-eqep.c +3 -2
-       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 err_pm;

This is not right. The devm_*() should not be followed by goto.

Quoted 1 line

+ }

...

drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 565

Quoted 4 lines
drivers/counter/ti-eqep.c +4 -0
+err_pm:
+       pm_runtime_put_sync(dev);
+       pm_runtime_disable(dev);
+       return err;

You have to use the respective devm_pm_*() at the same time.

Quoted 8 lines

...

William, this patch should not be applied (or should be reverted) as in current form it replaces one issue by another.

--
With Best Regards,
Andy Shevchenko

I'll revert for now. Would the proper fix be to replace all pm_runtime_*() with their respective devm_pm_*() calls?

William Breathitt Gray

#5 lore raw
Quoted 2 lines · William Breathitt Gray
Quoted 1 line · Andy Shevchenko

On Mon, May 25, 2026 at 5:21 PM Stepan Ionichev <[email protected]> wrote:

...

Quoted 12 lines
Quoted 12 lines

drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 553

Quoted 8 lines
        pm_runtime_get_sync(dev);

        clk = devm_clk_get_enabled(dev, NULL);
drivers/counter/ti-eqep.c +3 -2
-       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 err_pm;

This is not right. The devm_*() should not be followed by goto.

Quoted 1 line

+ }

...

Quoted 7 lines
Quoted 7 lines

drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 565

Quoted 5 lines
drivers/counter/ti-eqep.c +4 -0
+err_pm:
+       pm_runtime_put_sync(dev);
+       pm_runtime_disable(dev);
+       return err;

You have to use the respective devm_pm_*() at the same time.

...

Quoted 5 lines
Quoted 2 lines

William, this patch should not be applied (or should be reverted) as in current form it replaces one issue by another.

I'll revert for now. Would the proper fix be to replace all pm_runtime_*() with their respective devm_pm_*() calls?

Not all, but the ones that are opposite to pm_runtime_put*()/pm_runtime_disable(). It should be done carefully as well as PM runtime may be required before final registering of the device to access the registers (I haven't checked the driver, so I don't know if simple use devm_pm_*() will be enough).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 2 lines

I'll revert for now. Would the proper fix be to replace all pm_runtime_*() with their respective devm_pm_*() calls?

Not all, but the ones that are opposite to pm_runtime_put*()/pm_runtime_disable(). It should be done carefully as well as PM runtime may be required before final registering of the device to access the registers (I haven't checked the driver, so I don't know if simple use devm_pm_*() will be enough).

The eqep driver has no runtime suspend/resume callbacks - it only resumes in probe so that devm_clk_get_enabled() and counter_add() can reach the registers. So devm_pm_runtime_enable() plus pm_runtime_resume_and_get() before the clock get, with a devm action for the put, keeps the device resumed across registration and unwinds in reverse order on the error paths and on unbind. I'll send a v3 along those lines.

Stepan