Skip to contentSkip to conversation

drm/mali-dp: Fix runtime PM leak in malidp_crtc_atomic_enable()

PATCH In review Wentao Liang 3 participants 3 messages Sep 16

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

PATCH 1/1 drm/mali-dp: Fix runtime PM leak in malidp_crtc_atomic_enable()

malidp_crtc_atomic_enable() resumes the device with pm_runtime_get_sync() and returns early when the resume fails. The runtime PM usage count is incremented by pm_runtime_get_sync() even when the resume fails, so returning without dropping the reference leaks it and, once the error has been hit, prevents the device from ever suspending again.

Drop the runtime PM reference with pm_runtime_put_noidle() on the resume failure path before returning.

Fixes 85f6421889ec ("drm: mali-dp: Enable power management for the device.")
---
 drivers/gpu/drm/arm/malidp_crtc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/arm/malidp_crtc.c +1 -0
index 18e6157b1047..a2c6e536c55d 100644
@@ -56,6 +56,7 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc,
 
 	if (err < 0) {
 		DRM_DEBUG_DRIVER("Failed to enable runtime power management: %d\n", err);
+		pm_runtime_put_noidle(crtc->dev->dev);
 		return;
 	}
 
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] drm/malidp: runtime PM usage counter underflow in malidp_crtc_atomic_disable() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/malidp: runtime PM usage counter underflow in malidp_crtc_atomic_disable() --

commit 3492dcc2c28d3962cf4a64dc34d1fb164aaf6580
Author: Wentao Liang <[email protected]>

drm/mali-dp: Fix runtime PM leak in malidp_crtc_atomic_enable()

This patch drops the runtime PM reference with pm_runtime_put_noidle() on the resume failure path in malidp_crtc_atomic_enable(). This is intended to fix a reference leak when pm_runtime_get_sync() fails.

drivers/gpu/drm/arm/malidp_crtc.c static void malidp_crtc_atomic_enable(struct drm_crtc *crtc, · line 59

Quoted 9 lines
drivers/gpu/drm/arm/malidp_crtc.c +1 -0
index 157ff148efe7a..ec7b9db8b0b45 100644
@@ -56,6 +56,7 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc,
 
 	if (err < 0) {
 		DRM_DEBUG_DRIVER("Failed to enable runtime power management: %d\n", err);
+		pm_runtime_put_noidle(crtc->dev->dev);

[Severity: High]
Could this addition cause a runtime PM usage counter underflow when the CRTC is later disabled?

Because malidp_crtc_atomic_enable() returns void, the DRM core still considers the CRTC active even if it returns early on error here. When the CRTC is later disabled, malidp_crtc_atomic_disable() will be unconditionally called, which executes its own pm_runtime_put():

drivers/gpu/drm/arm/malidp_crtc.c:malidp_crtc_atomic_disable() {
	...
	clk_disable_unprepare(hwdev->pxlclk);

	pm_runtime_put(crtc->dev->dev);
}

If we drop the PM reference here on the error path, wouldn't the later call to pm_runtime_put() in malidp_crtc_atomic_disable() result in a double-put and underflow the PM usage counter?

Quoted 3 lines
drivers/gpu/drm/arm/malidp_crtc.c +0 -0
 		return;
 	}
 
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Wentao Liang
Quoted 7 lines · Wentao Liang

malidp_crtc_atomic_enable() resumes the device with pm_runtime_get_sync() and returns early when the resume fails. The runtime PM usage count is incremented by pm_runtime_get_sync() even when the resume fails, so returning without dropping the reference leaks it and, once the error has been hit, prevents the device from ever suspending again.

Quoted 6 lines

Drop the runtime PM reference with pm_runtime_put_noidle() on the resume failure path before returning.

Fixes 85f6421889ec ("drm: mali-dp: Enable power management for the device.")

I will push the patch to drm-misc-fixes.

Best regards,
Liviu

Quoted 19 lines
---
 drivers/gpu/drm/arm/malidp_crtc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/arm/malidp_crtc.c +1 -0
index 18e6157b1047..a2c6e536c55d 100644
@@ -56,6 +56,7 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc,
 
 	if (err < 0) {
 		DRM_DEBUG_DRIVER("Failed to enable runtime power management: %d\n", err);
+		pm_runtime_put_noidle(crtc->dev->dev);
 		return;
 	}
 
Signature · 1 line
2.34.1
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯