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

From: Felix Gu

Date: Fri Apr 17 2026 - 12:10:19 EST


In ti_eqep_probe(), if devm_clk_get_enabled() fails, the function
returns without cleaning up the runtime PM state.

Switch to devm functions to fix the problem and remove unneeded
remove() callback.

Fixes: 0cf81c73e4c6 ("counter: ti-eqep: enable clock at probe")
Signed-off-by: Felix Gu <ustc.gu@xxxxxxxxx>
---
Changes in v2:
- Switch to devm functions to fix David's comment.
- Link to v1: https://lore.kernel.org/r/20260417-ti-eqep-v1-1-a7db4642d9d0@xxxxxxxxx
---
drivers/counter/ti-eqep.c | 33 +++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
index d21c157e531a..08dc6d0ad5e4 100644
--- a/drivers/counter/ti-eqep.c
+++ b/drivers/counter/ti-eqep.c
@@ -492,6 +492,11 @@ static const struct regmap_config ti_eqep_regmap16_config = {
.max_register = QCPRDLAT,
};

+static void pm_put_sync(void *data)
+{
+ pm_runtime_put_sync(data);
+}
+
static int ti_eqep_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -544,31 +549,20 @@ static int ti_eqep_probe(struct platform_device *pdev)
* parent PWMSS bus driver. On AM17xx, this comes from the PSC power
* domain.
*/
- pm_runtime_enable(dev);
+ err = devm_pm_runtime_enable(dev);
+ if (err)
+ return err;
+
pm_runtime_get_sync(dev);
+ err = devm_add_action_or_reset(dev, pm_put_sync, dev);
+ if (err)
+ return err;

clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(clk))
return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");

- err = counter_add(counter);
- if (err < 0) {
- pm_runtime_put_sync(dev);
- pm_runtime_disable(dev);
- return err;
- }
-
- return 0;
-}
-
-static void ti_eqep_remove(struct platform_device *pdev)
-{
- struct counter_device *counter = platform_get_drvdata(pdev);
- struct device *dev = &pdev->dev;
-
- counter_unregister(counter);
- pm_runtime_put_sync(dev);
- pm_runtime_disable(dev);
+ return devm_counter_add(dev, counter);
}

static const struct of_device_id ti_eqep_of_match[] = {
@@ -580,7 +574,6 @@ MODULE_DEVICE_TABLE(of, ti_eqep_of_match);

static struct platform_driver ti_eqep_driver = {
.probe = ti_eqep_probe,
- .remove = ti_eqep_remove,
.driver = {
.name = "ti-eqep-cnt",
.of_match_table = ti_eqep_of_match,

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

Best regards,
--
Felix Gu <ustc.gu@xxxxxxxxx>