counter: ti-eqep: fix runtime PM leak in probe error path
Subsystems (3)
PATCH v2 1/1 counter: ti-eqep: fix runtime PM leak in probe error path
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.
---
Changes in v2:
- Switch to devm functions to fix David's comment.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/counter/ti-eqep.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/counter/ti-eqep.c +13 -20
@@ -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,
Signature · 1 line
Felix Gu <[email protected]>
David Lechner
reviewerQuoted 21 lines · Felix Gu
In
ti_eqep_probe(), ifdevm_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 <[email protected]>---
Changes in v2:
- Switch to devm functions to fix David's comment.
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/counter/ti-eqep.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)drivers/counter/ti-eqep.c +0
-0
drivers/counter/ti-eqep.c static const struct regmap_config ti_eqep_regmap16_config = { · line 495
Quoted 4 lines
drivers/counter/ti-eqep.c +1
-0@@ -492,6 +492,11 @@ static const struct regmap_config ti_eqep_regmap16_config = { .max_register = QCPRDLAT, }; +static void pm_put_sync (void *data)
This should have ti_eqep_ prefix in function name.
Quoted 8 lines
drivers/counter/ti-eqep.c +4
-0+{ +pm_runtime_put_sync (data); +} +static int ti_eqep_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 557
Quoted 10 lines
drivers/counter/ti-eqep.c +5
-1@@ -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);
I have no idea if this is OK or not. It seems like devm_pm_runtime_get_sync() would exist already if it was OK. So that makes me think it is not OK.
I added PM mailing list to see if anyone can advise.
Quoted 16 lines
drivers/counter/ti-eqep.c +2
-9+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 ; -}
drivers/counter/ti-eqep.c static int ti_eqep_probe(struct platform_device *pdev) · line 565
Quoted 10 lines
drivers/counter/ti-eqep.c +1
-9- -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);
Using devm_counter_add() is not part of the fix, so should be in a separate patch.
Quoted 17 lines
drivers/counter/ti-eqep.c +0
-2}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-8efb9cc713eaBest regards,