Skip to contentSkip to conversation

watchdog: starfive-wdt: Fix PM reference leak in probe error path

PATCH In review Kery Qi 2 participants 2 messages Jan 11 – Jan 12

Subsystems (2)
lore
Share & tools
lore

Kery Qi

author
#0 lore raw

PATCH 1/1 watchdog: starfive-wdt: Fix PM reference leak in probe error path

The PM reference count is not expected to be incremented on return in functions starfive_wdt_probe.

However, pm_runtime_get_sync will increment pm usage counter even failed. Forgetting to putting operation will result in a reference leak here.

Replace it with pm_runtime_resume_and_get to keep usage counter balanced.

Fixes db728ea9c7be ("drivers: watchdog: Add StarFive Watchdog driver")
---
 drivers/watchdog/starfive-wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/starfive-wdt.c +1 -1
index ed71d3960a0f..af55adc4a3c6 100644
@@ -446,7 +446,7 @@ static int starfive_wdt_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, wdt);
 	pm_runtime_enable(&pdev->dev);
 	if (pm_runtime_enabled(&pdev->dev)) {
-		ret = pm_runtime_get_sync(&pdev->dev);
+		ret = pm_runtime_resume_and_get(&pdev->dev);
 		if (ret < 0)
 			return ret;
 	} else {
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Kery Qi

The PM reference count is not expected to be incremented on return in functions starfive_wdt_probe.

However, pm_runtime_get_sync will increment pm usage counter even failed. Forgetting to putting operation will result in a reference leak here.

Quoted 5 lines

Replace it with pm_runtime_resume_and_get to keep usage counter balanced.

Fixes db728ea9c7be ("drivers: watchdog: Add StarFive Watchdog driver")
Quoted 17 lines
---
  drivers/watchdog/starfive-wdt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/starfive-wdt.c +1 -1
index ed71d3960a0f..af55adc4a3c6 100644
@@ -446,7 +446,7 @@ static int starfive_wdt_probe(struct platform_device *pdev)
  	platform_set_drvdata(pdev, wdt);
  	pm_runtime_enable(&pdev->dev);
  	if (pm_runtime_enabled(&pdev->dev)) {
-		ret = pm_runtime_get_sync(&pdev->dev);
+		ret = pm_runtime_resume_and_get(&pdev->dev);
  		if (ret < 0)
  			return ret;
  	} else {