diff mbox series

drm/bridge: Add missing pm_runtime_put_sync

Message ID 1642606560-32287-1-git-send-email-lyz_cs@pku.edu.cn (mailing list archive)
State New, archived
Headers show
Series drm/bridge: Add missing pm_runtime_put_sync | expand

Commit Message

刘永志 Jan. 19, 2022, 3:36 p.m. UTC
pm_runtime_get_sync() will increase the rumtime PM counter
even it returns an error. Thus a pairing decrement is needed
to prevent refcount leak. Fix this by replacing this API with
pm_runtime_resume_and_get(), which will not change the runtime
PM counter on error. Besides, a matching decrement is needed
on the error handling path to keep the counter balanced.

Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn>
---
 drivers/gpu/drm/bridge/nwl-dsi.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Laurent Pinchart Jan. 23, 2022, 8:08 p.m. UTC | #1
Hi Yongzhi,

Thank you for the patch.

On Wed, Jan 19, 2022 at 07:36:00AM -0800, Yongzhi Liu wrote:
> pm_runtime_get_sync() will increase the rumtime PM counter
> even it returns an error. Thus a pairing decrement is needed
> to prevent refcount leak. Fix this by replacing this API with
> pm_runtime_resume_and_get(), which will not change the runtime
> PM counter on error. Besides, a matching decrement is needed
> on the error handling path to keep the counter balanced.
> 
> Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn>
> ---
>  drivers/gpu/drm/bridge/nwl-dsi.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c
> index 9282e61..e7dce5a 100644
> --- a/drivers/gpu/drm/bridge/nwl-dsi.c
> +++ b/drivers/gpu/drm/bridge/nwl-dsi.c
> @@ -862,18 +862,19 @@ nwl_dsi_bridge_mode_set(struct drm_bridge *bridge,
>  	memcpy(&dsi->mode, adjusted_mode, sizeof(dsi->mode));
>  	drm_mode_debug_printmodeline(adjusted_mode);
>  
> -	pm_runtime_get_sync(dev);
> +	if (pm_runtime_resume_and_get(dev) < 0)
> +		return;
>  
>  	if (clk_prepare_enable(dsi->lcdif_clk) < 0)
> -		return;
> +		goto runtime_put;
>  	if (clk_prepare_enable(dsi->core_clk) < 0)
> -		return;
> +		goto runtime_put;
>  
>  	/* Step 1 from DSI reset-out instructions */
>  	ret = reset_control_deassert(dsi->rst_pclk);
>  	if (ret < 0) {
>  		DRM_DEV_ERROR(dev, "Failed to deassert PCLK: %d\n", ret);
> -		return;
> +		goto runtime_put;
>  	}
>  
>  	/* Step 2 from DSI reset-out instructions */
> @@ -883,13 +884,17 @@ nwl_dsi_bridge_mode_set(struct drm_bridge *bridge,
>  	ret = reset_control_deassert(dsi->rst_esc);
>  	if (ret < 0) {
>  		DRM_DEV_ERROR(dev, "Failed to deassert ESC: %d\n", ret);
> -		return;
> +		goto runtime_put;
>  	}
>  	ret = reset_control_deassert(dsi->rst_byte);
>  	if (ret < 0) {
>  		DRM_DEV_ERROR(dev, "Failed to deassert BYTE: %d\n", ret);
> -		return;
> +		goto runtime_put;
>  	}

You need a return here, otherwise you will unconditionally call
pm_runtime_put_sync() even on success.

> +
> +runtime_put:
> +	pm_runtime_put_sync(dev);
> +	return;

You can drop the return here.

>  }
>  
>  static void
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c
index 9282e61..e7dce5a 100644
--- a/drivers/gpu/drm/bridge/nwl-dsi.c
+++ b/drivers/gpu/drm/bridge/nwl-dsi.c
@@ -862,18 +862,19 @@  nwl_dsi_bridge_mode_set(struct drm_bridge *bridge,
 	memcpy(&dsi->mode, adjusted_mode, sizeof(dsi->mode));
 	drm_mode_debug_printmodeline(adjusted_mode);
 
-	pm_runtime_get_sync(dev);
+	if (pm_runtime_resume_and_get(dev) < 0)
+		return;
 
 	if (clk_prepare_enable(dsi->lcdif_clk) < 0)
-		return;
+		goto runtime_put;
 	if (clk_prepare_enable(dsi->core_clk) < 0)
-		return;
+		goto runtime_put;
 
 	/* Step 1 from DSI reset-out instructions */
 	ret = reset_control_deassert(dsi->rst_pclk);
 	if (ret < 0) {
 		DRM_DEV_ERROR(dev, "Failed to deassert PCLK: %d\n", ret);
-		return;
+		goto runtime_put;
 	}
 
 	/* Step 2 from DSI reset-out instructions */
@@ -883,13 +884,17 @@  nwl_dsi_bridge_mode_set(struct drm_bridge *bridge,
 	ret = reset_control_deassert(dsi->rst_esc);
 	if (ret < 0) {
 		DRM_DEV_ERROR(dev, "Failed to deassert ESC: %d\n", ret);
-		return;
+		goto runtime_put;
 	}
 	ret = reset_control_deassert(dsi->rst_byte);
 	if (ret < 0) {
 		DRM_DEV_ERROR(dev, "Failed to deassert BYTE: %d\n", ret);
-		return;
+		goto runtime_put;
 	}
+
+runtime_put:
+	pm_runtime_put_sync(dev);
+	return;
 }
 
 static void