Skip to contentSkip to conversation

counter: ti-eqep: Fix runtime PM error handling in probe

PATCH In review [email protected] 2 participants 3 messages Sep 22 – Nov 2

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

PATCH 1/1 counter: ti-eqep: Fix runtime PM error handling in probe

From: bui duc phuc <[email protected]>

pm_runtime_get_sync() errors were not checked, and if devm_clk_get_enabled() failed afterwards, the function returned without calling pm_runtime_put_sync()/pm_runtime_disable(), leaking the runtime PM usage count.

Switch to pm_runtime_resume_and_get() and add proper error unwinding via goto labels so every failure path after pm_runtime_enable() is cleaned up correctly.

Fixes f213729f6796 ("counter: new TI eQEP driver")
---
 drivers/counter/ti-eqep.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/counter/ti-eqep.c +19 -8
index 0dda3f2b14c7..698a9920f20d 100644
@@ -544,20 +544,31 @@ static int ti_eqep_probe(struct platform_device *pdev)
 	 * domain.
 	 */
 	pm_runtime_enable(dev);
-	pm_runtime_get_sync(dev);
+	err = pm_runtime_resume_and_get(dev);
+	if (err < 0) {
+		dev_err_probe(dev, err, "failed to enable runtime PM\n");
+		goto err_runtime_disable;
+	}
 
 	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_runtime_put;
+	}
 
 	err = counter_add(counter);
-	if (err < 0) {
-		pm_runtime_put_sync(dev);
-		pm_runtime_disable(dev);
-		return err;
-	}
+	if (err < 0)
+		goto err_runtime_put;
 
 	return 0;
+
+err_runtime_put:
+	pm_runtime_put_sync(dev);
+err_runtime_disable:
+	pm_runtime_disable(dev);
+
+	return err;
 }
 
 static void ti_eqep_remove(struct platform_device *pdev)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · On Tue, Sep 22, 2026 at 10:21:46AM +0700, [email protected] wrote:

From: bui duc phuc <[email protected]>

pm_runtime_get_sync() errors were not checked, and if devm_clk_get_enabled() failed afterwards, the function returned without calling pm_runtime_put_sync()/pm_runtime_disable(), leaking the runtime PM usage count.

Quoted 6 lines

Switch to pm_runtime_resume_and_get() and add proper error unwinding via goto labels so every failure path after pm_runtime_enable() is cleaned up correctly.

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

Hello,

This patch looks similar to another we're considering for ti-eqep.[^1] Perhaps you can provide a review or comment in that discussion thread so we can address this issue together.

William Breathitt Gray

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

Quoted 51 lines
---
 drivers/counter/ti-eqep.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/counter/ti-eqep.c +19 -9
index 0dda3f2b14c7..698a9920f20d 100644
@@ -544,20 +544,31 @@ static int ti_eqep_probe(struct platform_device *pdev)
 	 * domain.
 	 */
 	pm_runtime_enable(dev);
-	pm_runtime_get_sync(dev);
+	err = pm_runtime_resume_and_get(dev);
+	if (err < 0) {
+		dev_err_probe(dev, err, "failed to enable runtime PM\n");
+		goto err_runtime_disable;
+	}
 
 	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_runtime_put;
+	}
 
 	err = counter_add(counter);
-	if (err < 0) {
-		pm_runtime_put_sync(dev);
-		pm_runtime_disable(dev);
-		return err;
-	}
+	if (err < 0)
+		goto err_runtime_put;
 
 	return 0;
+
+err_runtime_put:
+	pm_runtime_put_sync(dev);
+err_runtime_disable:
+	pm_runtime_disable(dev);
+
+	return err;
 }
 
 static void ti_eqep_remove(struct platform_device *pdev)
--

2.43.0

#2 lore raw

Hi William,

Quoted 7 lines

This patch looks similar to another we're considering for ti-eqep.[^1] Perhaps you can provide a review or comment in that discussion thread so we can address this issue together.

William Breathitt Gray

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

Thanks for pointing that out.
I'll drop this patch and follow up in that thread.

Besst regards,
Phuc