* [PATCH] drm/bridge: Add missing pm_runtime_put_sync
@ 2022-01-19 15:36 Yongzhi Liu
2022-01-23 20:08 ` Laurent Pinchart
0 siblings, 1 reply; 5+ messages in thread
From: Yongzhi Liu @ 2022-01-19 15:36 UTC (permalink / raw)
To: a.hajda, narmstrong, robert.foss, Laurent.pinchart, jonas,
jernej.skrabec, airlied, daniel
Cc: Yongzhi Liu, linux-kernel, dri-devel
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;
}
+
+runtime_put:
+ pm_runtime_put_sync(dev);
+ return;
}
static void
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/bridge: Add missing pm_runtime_put_sync
2022-01-19 15:36 [PATCH] drm/bridge: Add missing pm_runtime_put_sync Yongzhi Liu
@ 2022-01-23 20:08 ` Laurent Pinchart
2022-01-24 7:20 ` [PATCH v2] " Yongzhi Liu
0 siblings, 1 reply; 5+ messages in thread
From: Laurent Pinchart @ 2022-01-23 20:08 UTC (permalink / raw)
To: Yongzhi Liu
Cc: jonas, airlied, dri-devel, narmstrong, linux-kernel,
jernej.skrabec, a.hajda, robert.foss
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
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] drm/bridge: Add missing pm_runtime_put_sync
2022-01-23 20:08 ` Laurent Pinchart
@ 2022-01-24 7:20 ` Yongzhi Liu
2022-01-27 1:10 ` Laurent Pinchart
0 siblings, 1 reply; 5+ messages in thread
From: Yongzhi Liu @ 2022-01-24 7:20 UTC (permalink / raw)
To: a.hajda, narmstrong, robert.foss, Laurent.pinchart, jonas,
jernej.skrabec, airlied, daniel
Cc: Yongzhi Liu, linux-kernel, dri-devel
pm_runtime_get_sync() will increase the rumtime PM counter
even when 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 | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c
index 9282e61..30aacd9 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,18 @@ 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;
}
+
+ return;
+
+runtime_put:
+ pm_runtime_put_sync(dev);
}
static void
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/bridge: Add missing pm_runtime_put_sync
2022-01-24 7:20 ` [PATCH v2] " Yongzhi Liu
@ 2022-01-27 1:10 ` Laurent Pinchart
2022-01-31 15:33 ` Robert Foss
0 siblings, 1 reply; 5+ messages in thread
From: Laurent Pinchart @ 2022-01-27 1:10 UTC (permalink / raw)
To: Yongzhi Liu
Cc: jonas, airlied, dri-devel, narmstrong, linux-kernel,
jernej.skrabec, a.hajda, robert.foss
Hi Yongzhi,
Thank you for the patch.
On Sun, Jan 23, 2022 at 11:20:35PM -0800, Yongzhi Liu wrote:
> pm_runtime_get_sync() will increase the rumtime PM counter
> even when 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>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> drivers/gpu/drm/bridge/nwl-dsi.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c
> index 9282e61..30aacd9 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,18 @@ 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;
> }
> +
> + return;
> +
> +runtime_put:
> + pm_runtime_put_sync(dev);
> }
>
> static void
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/bridge: Add missing pm_runtime_put_sync
2022-01-27 1:10 ` Laurent Pinchart
@ 2022-01-31 15:33 ` Robert Foss
0 siblings, 0 replies; 5+ messages in thread
From: Robert Foss @ 2022-01-31 15:33 UTC (permalink / raw)
To: Laurent Pinchart
Cc: jonas, Yongzhi Liu, airlied, narmstrong, linux-kernel,
jernej.skrabec, a.hajda, dri-devel
On Thu, 27 Jan 2022 at 02:10, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Yongzhi,
>
> Thank you for the patch.
>
> On Sun, Jan 23, 2022 at 11:20:35PM -0800, Yongzhi Liu wrote:
> > pm_runtime_get_sync() will increase the rumtime PM counter
> > even when 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>
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> > ---
> > drivers/gpu/drm/bridge/nwl-dsi.c | 18 ++++++++++++------
> > 1 file changed, 12 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c
> > index 9282e61..30aacd9 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,18 @@ 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;
> > }
> > +
> > + return;
> > +
> > +runtime_put:
> > + pm_runtime_put_sync(dev);
> > }
> >
> > static void
Applied to drm-misc-next.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-31 15:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19 15:36 [PATCH] drm/bridge: Add missing pm_runtime_put_sync Yongzhi Liu
2022-01-23 20:08 ` Laurent Pinchart
2022-01-24 7:20 ` [PATCH v2] " Yongzhi Liu
2022-01-27 1:10 ` Laurent Pinchart
2022-01-31 15:33 ` Robert Foss
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).