drm/bridge: cdns-dsi: Fix runtime PM leak in cdns_dsi_bridge_atomic_pre_enable()
Subsystems (4)
PATCH 1/1 drm/bridge: cdns-dsi: Fix runtime PM leak in cdns_dsi_bridge_atomic_pre_enable()
cdns_dsi_bridge_atomic_pre_enable() resumes the DSI controller with pm_runtime_get_sync() and returns early with a WARN_ON() when the resume fails. pm_runtime_get_sync() increments the runtime PM usage count even when it fails, so returning without dropping the reference leaks it and prevents the device from ever suspending again once the error has been hit.
Drop the runtime PM reference with pm_runtime_put_noidle() on the resume failure path before returning.
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +3 -1
@@ -733,8 +733,10 @@ static void cdns_dsi_bridge_atomic_pre_enable(struct drm_bridge *bridge,* enable their streams. */ -if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) +if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) { +pm_runtime_put_noidle (dsi->base.dev);return ; + } new_bridge_state =drm_atomic_get_new_bridge_state (state, bridge);if (WARN_ON (!new_bridge_state))
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] drm/cdns-dsi: double pm_runtime_put() causes usage counter underflow --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/cdns-dsi: double pm_runtime_put() causes usage counter underflow --
commit 863c1242b6ff6841137bcc0956d0095317384036
Author: Wentao Liang <[email protected]>
drm/bridge: cdns-dsi: Fix runtime PM leak in cdns_dsi_bridge_atomic_pre_enable()
This commit attempts to fix a runtime PM leak when pm_runtime_get_sync() fails by adding a call to pm_runtime_put_noidle(). The function then returns early.
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c static void cdns_dsi_bridge_atomic_pre_enable(struct drm_bridge *bridge, · line 737
Quoted 11 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +2
-1@@ -733,8 +733,10 @@ static void cdns_dsi_bridge_atomic_pre_enable(struct drm_bridge *bridge,* enable their streams. */ -if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) +if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) { +pm_runtime_put_noidle (dsi->base.dev);
[Severity: Medium]
Will this lead to a double-put of the runtime PM reference?
Since cdns_dsi_bridge_atomic_pre_enable() returns void, the DRM core is unaware that the bridge failed to enable. The atomic commit continues normally, and when the bridge is later disabled, cdns_dsi_bridge_atomic_post_disable() is called unconditionally.
If we look at cdns_dsi_bridge_atomic_post_disable(), it executes a second put during teardown:
static void cdns_dsi_bridge_atomic_post_disable(...)
{
...
pm_runtime_put(dsi->base.dev);
}Wouldn't this decrement the usage count again and cause a runtime PM usage counter underflow?
Quoted 5 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1
-0return ; + } new_bridge_state =drm_atomic_get_new_bridge_state (state, bridge);if (WARN_ON (!new_bridge_state))
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Laurent Pinchart
reviewerQuoted 22 lines · Wentao Liang
cdns_dsi_bridge_atomic_pre_enable()resumes the DSI controller withpm_runtime_get_sync()and returns early with aWARN_ON()when the resume fails.pm_runtime_get_sync()increments the runtime PM usage count even when it fails, so returning without dropping the reference leaks it and prevents the device from ever suspending again once the error has been hit.Drop the runtime PM reference with
pm_runtime_put_noidle()on the resume failure path before returning.Fixes e19233955d9e ("drm/bridge: Add Cadence DSI driver")Signed-off-by Wentao Liang <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c static void cdns_dsi_bridge_atomic_pre_enable(struct drm_bridge *bridge, · line 739
Quoted 8 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +3
-1@@ -733,8 +733,10 @@ static void cdns_dsi_bridge_atomic_pre_enable(struct drm_bridge *bridge,* enable their streams. */ -if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) +if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) { +pm_runtime_put_noidle (dsi->base.dev);return ; + }
Anything wrong with pm_runtime_resume_and_get() ?
Quoted 3 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0new_bridge_state =drm_atomic_get_new_bridge_state (state, bridge);if (WARN_ON (!new_bridge_state))
Signature · 3 lines
Regards, Laurent Pinchart
PATCH v2 1/1 drm/bridge: cdns-dsi: Handle runtime PM resume failures in bridge callbacks
cdns_dsi_bridge_atomic_pre_enable() uses pm_runtime_get_sync() to resume the DSI controller. The helper increments the runtime PM usage count even if the resume fails.
The corresponding post-disable callback unconditionally accesses the controller registers, releases the PHY, and drops the runtime PM reference. However, the DRM bridge pre-enable callback returns void, so a failed resume does not prevent the later post-disable callback from running.
Use pm_runtime_resume_and_get() to avoid retaining a usage count on failure. Track successful runtime PM acquisition and skip post-disable cleanup if pre-enable failed.
Also move the bridge state validation before runtime PM acquisition.
This change was prepared with assistance from DeepSeek-V4.1-Flash and GPT-6.1-Sol.
---
Changes in v2:
- Sorry for the very late reply, and thanks for the review.
- Use pm_runtime_resume_and_get() as suggested by Laurent.
- Track successful runtime PM acquisition.
- Skip post-disable cleanup after a failed pre-enable.
- Validate the bridge state before acquiring the PM reference.
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 12 +++++++++--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +9 -3
@@ -613,6 +613,9 @@ static void cdns_dsi_bridge_atomic_post_disable(struct drm_bridge *bridge,* disable their streams. */ +if (!dsi->bridge_pm_active) +return ; + val =readl (dsi->regs +MCTL_MAIN_DATA_CTL ); val &= ~(IF_VID_SELECT_MASK |IF_VID_MODE |VID_EN |HOST_EOT_GEN |DISP_EOT_GEN );
@@ -630,6 +633,7 @@ static void cdns_dsi_bridge_atomic_post_disable(struct drm_bridge *bridge,phy_exit (dsi->dphy);pm_runtime_put (dsi->base.dev); + dsi->bridge_pm_active = false; }static void cdns_dsi_hs_init (struct cdns_dsi *dsi)
@@ -734,13 +738,15 @@ static void cdns_dsi_bridge_atomic_pre_enable(struct drm_bridge *bridge,* enable their streams. */ -if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) -return ; - new_bridge_state =drm_atomic_get_new_bridge_state (state, bridge);if (WARN_ON (!new_bridge_state))return ; +if (WARN_ON (pm_runtime_resume_and_get (dsi->base.dev) <0 )) +return ; + + dsi->bridge_pm_active = true; + dsi_state =to_cdns_dsi_bridge_state (new_bridge_state); dsi_cfg = dsi_state->dsi_cfg;
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.h +1 -0
@@ -76,6 +76,7 @@ struct cdns_dsi {struct clk *dsi_sys_clk;bool link_initialized;bool phy_initialized; +bool bridge_pm_active;struct phy *dphy; };
Hi Laurent,
Sorry for the very late reply, and thanks for the suggestion.
I agree that pm_runtime_resume_and_get() is preferable here.
I also noticed that cdns_dsi_bridge_atomic_post_disable() unconditionally accesses the controller registers and releases the PHY and runtime PM reference. Since the pre-enable callback returns void, the post-disable callback may still be invoked after a failed runtime resume.
I'll update the patch to use pm_runtime_resume_and_get() and track whether the runtime PM reference was successfully acquired, so that post-disable skips cleanup when pre-enable fails.
Thanks,
Wentao