mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/omap: Fix runtime PM imbalance in dsi_runtime_get
@ 2020-08-21  7:45 Dinghao Liu
  2020-08-21 12:06 ` Tomi Valkeinen
  0 siblings, 1 reply; 4+ messages in thread
From: Dinghao Liu @ 2020-08-21  7:45 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Tomi Valkeinen, David Airlie, Daniel Vetter, Laurent Pinchart,
	Sebastian Reichel, Tony Lindgren, zhengbin, Kevin Hilman,
	dri-devel, linux-kernel

pm_runtime_get_sync() increments the runtime PM usage counter
even when it returns an error code. However, users of
dsi_runtime_get(), a direct wrapper of pm_runtime_get_sync(),
assume that PM usage counter will not change on error. Thus a
pairing decrement is needed on the error handling path to keep
the counter balanced.

Fixes: 4fbafaf371be7 ("OMAP: DSS2: Use PM runtime & HWMOD support")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/gpu/drm/omapdrm/dss/dsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/dsi.c b/drivers/gpu/drm/omapdrm/dss/dsi.c
index eeccf40bae41..973bfa14a104 100644
--- a/drivers/gpu/drm/omapdrm/dss/dsi.c
+++ b/drivers/gpu/drm/omapdrm/dss/dsi.c
@@ -1112,8 +1112,11 @@ static int dsi_runtime_get(struct dsi_data *dsi)
 	DSSDBG("dsi_runtime_get\n");
 
 	r = pm_runtime_get_sync(dsi->dev);
-	WARN_ON(r < 0);
-	return r < 0 ? r : 0;
+	if (WARN_ON(r < 0)) {
+		pm_runtime_put_noidle(dsi->dev);
+		return r;
+	}
+	return 0;
 }
 
 static void dsi_runtime_put(struct dsi_data *dsi)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/omap: Fix runtime PM imbalance in dsi_runtime_get
  2020-08-21  7:45 [PATCH] drm/omap: Fix runtime PM imbalance in dsi_runtime_get Dinghao Liu
@ 2020-08-21 12:06 ` Tomi Valkeinen
  2020-08-22  6:00   ` dinghao.liu
  2020-08-22 10:48   ` Laurent Pinchart
  0 siblings, 2 replies; 4+ messages in thread
From: Tomi Valkeinen @ 2020-08-21 12:06 UTC (permalink / raw)
  To: Dinghao Liu, kjlu
  Cc: David Airlie, Daniel Vetter, Laurent Pinchart, Sebastian Reichel,
	Tony Lindgren, zhengbin, dri-devel, linux-kernel

Hi,

On 21/08/2020 10:45, Dinghao Liu wrote:
> pm_runtime_get_sync() increments the runtime PM usage counter
> even when it returns an error code. However, users of
> dsi_runtime_get(), a direct wrapper of pm_runtime_get_sync(),
> assume that PM usage counter will not change on error. Thus a
> pairing decrement is needed on the error handling path to keep
> the counter balanced.
> 
> Fixes: 4fbafaf371be7 ("OMAP: DSS2: Use PM runtime & HWMOD support")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/gpu/drm/omapdrm/dss/dsi.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/omapdrm/dss/dsi.c b/drivers/gpu/drm/omapdrm/dss/dsi.c
> index eeccf40bae41..973bfa14a104 100644
> --- a/drivers/gpu/drm/omapdrm/dss/dsi.c
> +++ b/drivers/gpu/drm/omapdrm/dss/dsi.c
> @@ -1112,8 +1112,11 @@ static int dsi_runtime_get(struct dsi_data *dsi)
>  	DSSDBG("dsi_runtime_get\n");
>  
>  	r = pm_runtime_get_sync(dsi->dev);
> -	WARN_ON(r < 0);
> -	return r < 0 ? r : 0;
> +	if (WARN_ON(r < 0)) {
> +		pm_runtime_put_noidle(dsi->dev);
> +		return r;
> +	}
> +	return 0;
>  }

Thanks! Good catch. I think this is broken in all the other modules in omapdrm too (e.g. dispc.c,
venc.c, etc).

Would you like to update the patch to cover the whole omapdrm?

 Tomi

-- 
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [PATCH] drm/omap: Fix runtime PM imbalance in dsi_runtime_get
  2020-08-21 12:06 ` Tomi Valkeinen
@ 2020-08-22  6:00   ` dinghao.liu
  2020-08-22 10:48   ` Laurent Pinchart
  1 sibling, 0 replies; 4+ messages in thread
From: dinghao.liu @ 2020-08-22  6:00 UTC (permalink / raw)
  To: Tomi Valkeinen
  Cc: kjlu, David Airlie, Daniel Vetter, Laurent Pinchart,
	Sebastian Reichel, Tony Lindgren, zhengbin, dri-devel,
	linux-kernel

> Hi,
> 
> On 21/08/2020 10:45, Dinghao Liu wrote:
> > pm_runtime_get_sync() increments the runtime PM usage counter
> > even when it returns an error code. However, users of
> > dsi_runtime_get(), a direct wrapper of pm_runtime_get_sync(),
> > assume that PM usage counter will not change on error. Thus a
> > pairing decrement is needed on the error handling path to keep
> > the counter balanced.
> > 
> > Fixes: 4fbafaf371be7 ("OMAP: DSS2: Use PM runtime & HWMOD support")
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/gpu/drm/omapdrm/dss/dsi.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/omapdrm/dss/dsi.c b/drivers/gpu/drm/omapdrm/dss/dsi.c
> > index eeccf40bae41..973bfa14a104 100644
> > --- a/drivers/gpu/drm/omapdrm/dss/dsi.c
> > +++ b/drivers/gpu/drm/omapdrm/dss/dsi.c
> > @@ -1112,8 +1112,11 @@ static int dsi_runtime_get(struct dsi_data *dsi)
> >  	DSSDBG("dsi_runtime_get\n");
> >  
> >  	r = pm_runtime_get_sync(dsi->dev);
> > -	WARN_ON(r < 0);
> > -	return r < 0 ? r : 0;
> > +	if (WARN_ON(r < 0)) {
> > +		pm_runtime_put_noidle(dsi->dev);
> > +		return r;
> > +	}
> > +	return 0;
> >  }
> 
> Thanks! Good catch. I think this is broken in all the other modules in omapdrm too (e.g. dispc.c,
> venc.c, etc).
> 
> Would you like to update the patch to cover the whole omapdrm?
> 

Sure. I will fix this soon.

Regards,
Dinghao

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/omap: Fix runtime PM imbalance in dsi_runtime_get
  2020-08-21 12:06 ` Tomi Valkeinen
  2020-08-22  6:00   ` dinghao.liu
@ 2020-08-22 10:48   ` Laurent Pinchart
  1 sibling, 0 replies; 4+ messages in thread
From: Laurent Pinchart @ 2020-08-22 10:48 UTC (permalink / raw)
  To: Tomi Valkeinen
  Cc: Dinghao Liu, kjlu, David Airlie, Daniel Vetter,
	Sebastian Reichel, Tony Lindgren, zhengbin, dri-devel,
	linux-kernel

Hi Tomi,

On Fri, Aug 21, 2020 at 03:06:59PM +0300, Tomi Valkeinen wrote:
> On 21/08/2020 10:45, Dinghao Liu wrote:
> > pm_runtime_get_sync() increments the runtime PM usage counter
> > even when it returns an error code. However, users of
> > dsi_runtime_get(), a direct wrapper of pm_runtime_get_sync(),
> > assume that PM usage counter will not change on error. Thus a
> > pairing decrement is needed on the error handling path to keep
> > the counter balanced.
> > 
> > Fixes: 4fbafaf371be7 ("OMAP: DSS2: Use PM runtime & HWMOD support")
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/gpu/drm/omapdrm/dss/dsi.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/omapdrm/dss/dsi.c b/drivers/gpu/drm/omapdrm/dss/dsi.c
> > index eeccf40bae41..973bfa14a104 100644
> > --- a/drivers/gpu/drm/omapdrm/dss/dsi.c
> > +++ b/drivers/gpu/drm/omapdrm/dss/dsi.c
> > @@ -1112,8 +1112,11 @@ static int dsi_runtime_get(struct dsi_data *dsi)
> >  	DSSDBG("dsi_runtime_get\n");
> >  
> >  	r = pm_runtime_get_sync(dsi->dev);
> > -	WARN_ON(r < 0);
> > -	return r < 0 ? r : 0;
> > +	if (WARN_ON(r < 0)) {
> > +		pm_runtime_put_noidle(dsi->dev);
> > +		return r;
> > +	}
> > +	return 0;
> >  }
> 
> Thanks! Good catch. I think this is broken in all the other modules in omapdrm too (e.g. dispc.c,
> venc.c, etc).
> 
> Would you like to update the patch to cover the whole omapdrm?

Just for yoru information, there has been quite a few similar patches
submitted all across the kernel. I believe this is an issue of the
pm_runtime_get_sync() API, which really shouldn't require a put() when
it fails. For drivers that really don't expect pm_runtime_get_sync() to
fail (no I2C access to a regulator for instance, only SoC-internal
operations) I've instead decided to ignore the error completely. I don't
think poluting the whole kernel code base with this kind of "fixes" is a
good idea.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-22 10:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21  7:45 [PATCH] drm/omap: Fix runtime PM imbalance in dsi_runtime_get Dinghao Liu
2020-08-21 12:06 ` Tomi Valkeinen
2020-08-22  6:00   ` dinghao.liu
2020-08-22 10:48   ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®