linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] media: vsp1: Fix runtime PM imbalance on error
@ 2020-06-08  5:29 Dinghao Liu
  2020-06-08 21:29 ` Kieran Bingham
  2020-06-16  2:56 ` Laurent Pinchart
  0 siblings, 2 replies; 3+ messages in thread
From: Dinghao Liu @ 2020-06-08  5:29 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Laurent Pinchart, Kieran Bingham, Mauro Carvalho Chehab,
	linux-media, linux-renesas-soc, linux-kernel

pm_runtime_get_sync() increments the runtime PM usage counter even
when it returns an error code. Thus a pairing decrement is needed on
the error handling path to keep the counter balanced.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: - Fix the imbalance in vsp1_device_get().
      Use vsp1_device_get() and vsp1_device_put()
      to replace pm_runtime_get_sync() and
      pm_runtime_put_sync() in vsp1_probe().
---
 drivers/media/platform/vsp1/vsp1_drv.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index c650e45bb0ad..dc62533cf32c 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -562,7 +562,12 @@ int vsp1_device_get(struct vsp1_device *vsp1)
 	int ret;
 
 	ret = pm_runtime_get_sync(vsp1->dev);
-	return ret < 0 ? ret : 0;
+	if (ret < 0) {
+		pm_runtime_put_noidle(vsp1->dev);
+		return ret;
+	}
+
+	return 0;
 }
 
 /*
@@ -845,12 +850,12 @@ static int vsp1_probe(struct platform_device *pdev)
 	/* Configure device parameters based on the version register. */
 	pm_runtime_enable(&pdev->dev);
 
-	ret = pm_runtime_get_sync(&pdev->dev);
+	ret = vsp1_device_get(vsp1);
 	if (ret < 0)
 		goto done;
 
 	vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
-	pm_runtime_put_sync(&pdev->dev);
+	vsp1_device_put(vsp1);
 
 	for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
 		if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==
-- 
2.17.1


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

* Re: [PATCH] [v2] media: vsp1: Fix runtime PM imbalance on error
  2020-06-08  5:29 [PATCH] [v2] media: vsp1: Fix runtime PM imbalance on error Dinghao Liu
@ 2020-06-08 21:29 ` Kieran Bingham
  2020-06-16  2:56 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Kieran Bingham @ 2020-06-08 21:29 UTC (permalink / raw)
  To: Dinghao Liu, kjlu
  Cc: Laurent Pinchart, Mauro Carvalho Chehab, linux-media,
	linux-renesas-soc, linux-kernel

Hi Dinghao,

On 08/06/2020 06:29, Dinghao Liu wrote:
> pm_runtime_get_sync() increments the runtime PM usage counter even
> when it returns an error code. Thus a pairing decrement is needed on
> the error handling path to keep the counter balanced.
> 

Looks good to me:

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
> 
> Changelog:
> 
> v2: - Fix the imbalance in vsp1_device_get().
>       Use vsp1_device_get() and vsp1_device_put()
>       to replace pm_runtime_get_sync() and
>       pm_runtime_put_sync() in vsp1_probe().

That looks like a helpful addition!

> ---
>  drivers/media/platform/vsp1/vsp1_drv.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
> index c650e45bb0ad..dc62533cf32c 100644
> --- a/drivers/media/platform/vsp1/vsp1_drv.c
> +++ b/drivers/media/platform/vsp1/vsp1_drv.c
> @@ -562,7 +562,12 @@ int vsp1_device_get(struct vsp1_device *vsp1)
>  	int ret;
>  
>  	ret = pm_runtime_get_sync(vsp1->dev);
> -	return ret < 0 ? ret : 0;
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(vsp1->dev);

Hrm... I was going to query the _noidle here, as I presume the device is
likely already idle ... but actually this looks like it simply adds
protection against decrementing the refcnt below zero, so it is likely
useful.



> +		return ret;
> +	}
> +
> +	return 0;
>  }
>  
>  /*
> @@ -845,12 +850,12 @@ static int vsp1_probe(struct platform_device *pdev)
>  	/* Configure device parameters based on the version register. */
>  	pm_runtime_enable(&pdev->dev);
>  
> -	ret = pm_runtime_get_sync(&pdev->dev);
> +	ret = vsp1_device_get(vsp1);
>  	if (ret < 0)
>  		goto done;
>  
>  	vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
> -	pm_runtime_put_sync(&pdev->dev);
> +	vsp1_device_put(vsp1);
>  
>  	for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
>  		if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==
> 


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

* Re: [PATCH] [v2] media: vsp1: Fix runtime PM imbalance on error
  2020-06-08  5:29 [PATCH] [v2] media: vsp1: Fix runtime PM imbalance on error Dinghao Liu
  2020-06-08 21:29 ` Kieran Bingham
@ 2020-06-16  2:56 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Pinchart @ 2020-06-16  2:56 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: kjlu, Kieran Bingham, Mauro Carvalho Chehab, linux-media,
	linux-renesas-soc, linux-kernel

Hello Dinghao,

Thank you for the patch.

On Mon, Jun 08, 2020 at 01:29:19PM +0800, Dinghao Liu wrote:
> pm_runtime_get_sync() increments the runtime PM usage counter even
> when it returns an error code. Thus a pairing decrement is needed on
> the error handling path to keep the counter balanced.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I have however received multiple similar patches recently, for different
drivers. I've CC'ed Rafael, the PM maintainer, in one of those e-mail
threads, and questioned whether we should really mass-patch drivers, or
fix the issue in pm_runtime_get_sync(). I'll defer pushing this patch
until that discussion comes to a conclusion.

> ---
> 
> Changelog:
> 
> v2: - Fix the imbalance in vsp1_device_get().
>       Use vsp1_device_get() and vsp1_device_put()
>       to replace pm_runtime_get_sync() and
>       pm_runtime_put_sync() in vsp1_probe().
> ---
>  drivers/media/platform/vsp1/vsp1_drv.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
> index c650e45bb0ad..dc62533cf32c 100644
> --- a/drivers/media/platform/vsp1/vsp1_drv.c
> +++ b/drivers/media/platform/vsp1/vsp1_drv.c
> @@ -562,7 +562,12 @@ int vsp1_device_get(struct vsp1_device *vsp1)
>  	int ret;
>  
>  	ret = pm_runtime_get_sync(vsp1->dev);
> -	return ret < 0 ? ret : 0;
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(vsp1->dev);
> +		return ret;
> +	}
> +
> +	return 0;
>  }
>  
>  /*
> @@ -845,12 +850,12 @@ static int vsp1_probe(struct platform_device *pdev)
>  	/* Configure device parameters based on the version register. */
>  	pm_runtime_enable(&pdev->dev);
>  
> -	ret = pm_runtime_get_sync(&pdev->dev);
> +	ret = vsp1_device_get(vsp1);
>  	if (ret < 0)
>  		goto done;
>  
>  	vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
> -	pm_runtime_put_sync(&pdev->dev);
> +	vsp1_device_put(vsp1);
>  
>  	for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
>  		if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==

-- 
Regards,

Laurent Pinchart

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

end of thread, other threads:[~2020-06-16  2:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-08  5:29 [PATCH] [v2] media: vsp1: Fix runtime PM imbalance on error Dinghao Liu
2020-06-08 21:29 ` Kieran Bingham
2020-06-16  2:56 ` Laurent Pinchart

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).