Skip to contentSkip to conversation

media: qcom: iris: fix runtime PM reference leaks

PATCH Superseded Hungyu Lin 3 participants 3 messages Jun 4

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 media: qcom: iris: fix runtime PM reference leaks

Use pm_runtime_resume_and_get() in iris_enable_power_domains() to avoid leaking a runtime PM usage count on failure.

Also ensure pm_runtime_put_sync() is always called in iris_disable_power_domains(), even when iris_opp_set_rate() fails, so runtime PM references remain balanced.

---
 drivers/media/platform/qcom/iris/iris_resources.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/platform/qcom/iris/iris_resources.c +4 -6
index 773f6548370a..f5e3341e1430 100644
@@ -78,11 +78,11 @@ int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev)
 	if (ret)
 		return ret;
 
-	ret = pm_runtime_get_sync(pd_dev);
-	if (ret < 0)
+	ret = pm_runtime_resume_and_get(pd_dev);
+	if (ret)
 		return ret;
 
-	return ret;
+	return 0;
 }
 
 int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
@@ -90,12 +90,10 @@ int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
 	int ret;
 
 	ret = iris_opp_set_rate(core->dev, 0);
-	if (ret)
-		return ret;
 
 	pm_runtime_put_sync(pd_dev);
 
-	return 0;
+	return ret;
 }
 
 static struct clk *iris_get_clk_by_type(struct iris_core *core, enum platform_clk_type clk_type)
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Resource leak (maximum performance state vote) on PM resume error path.
- [High] Unconditional execution of pm_runtime_put_sync() after pm_runtime_resume_and_get() failure causes PM usage counter underflow. --

commit 6abf56207cd4930a9c5add5c9255347bc4ca7e5a
Author: Hungyu Lin <[email protected]>

media: qcom: iris: fix runtime PM reference leaks

Use pm_runtime_resume_and_get() in iris_enable_power_domains() to avoid leaking a runtime PM usage count on failure.

Also ensure pm_runtime_put_sync() is always called in iris_disable_power_domains(), even when iris_opp_set_rate() fails, so runtime PM references remain balanced.

drivers/media/platform/qcom/iris/iris_resources.c int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev) · line 83

Quoted 13 lines
drivers/media/platform/qcom/iris/iris_resources.c +2 -2
index 773f6548370a2..f5e3341e14309 100644
@@ -78,11 +78,11 @@ int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev)
 	if (ret)
 		return ret;
 
-	ret = pm_runtime_get_sync(pd_dev);
-	if (ret < 0)
+	ret = pm_runtime_resume_and_get(pd_dev);
+	if (ret)
 		return ret;

[Severity: High]
This isn't a bug introduced by this patch, but does this leak the maximum performance state vote?

In iris_enable_power_domains(), iris_opp_set_rate() is called just before this snippet to request the maximum operating performance point. If the subsequent call to pm_runtime_resume_and_get() fails here, we return the error code without unwinding the OPP rate vote.

Could this leave the hardware permanently voting for maximum voltage and frequency?

drivers/media/platform/qcom/iris/iris_resources.c int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev) · line 86

Quoted 4 lines
drivers/media/platform/qcom/iris/iris_resources.c +1 -1
-	return ret;
+	return 0;
 }

[Severity: High]
This is a pre-existing issue, but I noticed a potential problem in other files regarding the PM usage counter underflowing when pm_runtime_resume_and_get() fails.

In iris_core_deinit():

drivers/media/platform/qcom/iris/iris_core.c:iris_core_deinit() {
    ...
    pm_runtime_resume_and_get(core->dev);

    mutex_lock(&core->lock);
    ...
    pm_runtime_put_sync(core->dev);
    ...
}

And similarly in iris_hfi_queue_cmd_write():

drivers/media/platform/qcom/iris/iris_hfi_queue.c:iris_hfi_queue_cmd_write() {
    ...
exit:
    pm_runtime_put_sync(core->dev);

    return ret;
}

Since pm_runtime_resume_and_get() automatically drops the PM usage count internally if it fails, executing pm_runtime_put_sync() unconditionally afterwards drops the count a second time.

Is it possible this drops the counter below its baseline and causes the device to prematurely suspend while in use by other threads?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Hungyu Lin
Quoted 7 lines · Hungyu Lin

Use pm_runtime_resume_and_get() in iris_enable_power_domains() to avoid leaking a runtime PM usage count on failure.

Also ensure pm_runtime_put_sync() is always called in iris_disable_power_domains(), even when iris_opp_set_rate() fails, so runtime PM references remain balanced.

Please add a fix tag for the fix patch.

Fixes bb8a95aa038e ("media: iris: implement power management")

Thanks,
Jie

Quoted 38 lines
---
  drivers/media/platform/qcom/iris/iris_resources.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/platform/qcom/iris/iris_resources.c +4 -6
index 773f6548370a..f5e3341e1430 100644
@@ -78,11 +78,11 @@ int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev)
  	if (ret)
  		return ret;
 
-	ret = pm_runtime_get_sync(pd_dev);
-	if (ret < 0)
+	ret = pm_runtime_resume_and_get(pd_dev);
+	if (ret)
  		return ret;
 
-	return ret;
+	return 0;
  }
 
  int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
@@ -90,12 +90,10 @@ int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
  	int ret;
 
  	ret = iris_opp_set_rate(core->dev, 0);
-	if (ret)
-		return ret;
 
  	pm_runtime_put_sync(pd_dev);
 
-	return 0;
+	return ret;
  }
 
  static struct clk *iris_get_clk_by_type(struct iris_core *core, enum platform_clk_type clk_type)