linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: coda: Fix runtime PM imbalance in coda_probe
@ 2020-05-23 10:03 Dinghao Liu
  2020-05-25 12:38 ` Philipp Zabel
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-05-23 10:03 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Philipp Zabel, Mauro Carvalho Chehab, linux-media, linux-kernel

When coda_firmware_request() returns an error code,
a pairing runtime PM usage counter decrement is needed
to keep the counter balanced.

Also, the caller expects coda_probe() to increase PM
usage counter, there should be a refcount decrement
in coda_remove() to keep the counter balanced.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/media/platform/coda/coda-common.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index d0d093dd8f7c..550e9a1266da 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -3119,6 +3119,8 @@ static int coda_probe(struct platform_device *pdev)
 	return 0;
 
 err_alloc_workqueue:
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
 	destroy_workqueue(dev->workqueue);
 err_v4l2_register:
 	v4l2_device_unregister(&dev->v4l2_dev);
@@ -3136,6 +3138,7 @@ static int coda_remove(struct platform_device *pdev)
 	}
 	if (dev->m2m_dev)
 		v4l2_m2m_release(dev->m2m_dev);
+	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	v4l2_device_unregister(&dev->v4l2_dev);
 	destroy_workqueue(dev->workqueue);
-- 
2.17.1


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

* Re: [PATCH] media: coda: Fix runtime PM imbalance in coda_probe
  2020-05-23 10:03 [PATCH] media: coda: Fix runtime PM imbalance in coda_probe Dinghao Liu
@ 2020-05-25 12:38 ` Philipp Zabel
  2020-05-25 12:52   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Philipp Zabel @ 2020-05-25 12:38 UTC (permalink / raw)
  To: Dinghao Liu; +Cc: kjlu, Mauro Carvalho Chehab, linux-media, linux-kernel

Hi Dinghao,

thank you for the patch! The first part is fine, but I think the second
part is not necessary, see below:

On Sat, May 23, 2020 at 06:03:32PM +0800, Dinghao Liu wrote:
> When coda_firmware_request() returns an error code,
> a pairing runtime PM usage counter decrement is needed
> to keep the counter balanced.
> 
> Also, the caller expects coda_probe() to increase PM
> usage counter, there should be a refcount decrement
> in coda_remove() to keep the counter balanced.

coda_probe() increments the usage counter only until coda_fw_callback()
decrements it again. Where is the imbalance?

> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/media/platform/coda/coda-common.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
> index d0d093dd8f7c..550e9a1266da 100644
> --- a/drivers/media/platform/coda/coda-common.c
> +++ b/drivers/media/platform/coda/coda-common.c
> @@ -3119,6 +3119,8 @@ static int coda_probe(struct platform_device *pdev)
>  	return 0;
>  
>  err_alloc_workqueue:
> +	pm_runtime_disable(&pdev->dev);
> +	pm_runtime_put_noidle(&pdev->dev);

These seem right, they balance out the pm_runtime_enable()
and pm_runtime_get_noresume() right before the error.

>  	destroy_workqueue(dev->workqueue);
>  err_v4l2_register:
>  	v4l2_device_unregister(&dev->v4l2_dev);
> @@ -3136,6 +3138,7 @@ static int coda_remove(struct platform_device *pdev)
>  	}
>  	if (dev->m2m_dev)
>  		v4l2_m2m_release(dev->m2m_dev);
> +	pm_runtime_put_noidle(&pdev->dev);

I think this is incorrect. There is one pm_runtime_get_noresume() in
coda_probe(), and one pm_runtime_put_sync() in coda_fw_callback().
By the time coda_remove() is called, balance is already restored.

regards
Philipp

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

* Re: Re: [PATCH] media: coda: Fix runtime PM imbalance in coda_probe
  2020-05-25 12:38 ` Philipp Zabel
@ 2020-05-25 12:52   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2020-05-25 12:52 UTC (permalink / raw)
  To: Philipp Zabel; +Cc: kjlu, Mauro Carvalho Chehab, linux-media, linux-kernel

> Hi Dinghao,
> 
> thank you for the patch! The first part is fine, but I think the second
> part is not necessary, see below:
> 
> On Sat, May 23, 2020 at 06:03:32PM +0800, Dinghao Liu wrote:
> > When coda_firmware_request() returns an error code,
> > a pairing runtime PM usage counter decrement is needed
> > to keep the counter balanced.
> > 
> > Also, the caller expects coda_probe() to increase PM
> > usage counter, there should be a refcount decrement
> > in coda_remove() to keep the counter balanced.
> 
> coda_probe() increments the usage counter only until coda_fw_callback()
> decrements it again. Where is the imbalance?
> 

You are right, I missed coda_firmware_request() before and 
thank you for your correction! I will fix this in the next
edition of patch.

Regards,
Dinghao

> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/media/platform/coda/coda-common.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
> > index d0d093dd8f7c..550e9a1266da 100644
> > --- a/drivers/media/platform/coda/coda-common.c
> > +++ b/drivers/media/platform/coda/coda-common.c
> > @@ -3119,6 +3119,8 @@ static int coda_probe(struct platform_device *pdev)
> >  	return 0;
> >  
> >  err_alloc_workqueue:
> > +	pm_runtime_disable(&pdev->dev);
> > +	pm_runtime_put_noidle(&pdev->dev);
> 
> These seem right, they balance out the pm_runtime_enable()
> and pm_runtime_get_noresume() right before the error.
> 
> >  	destroy_workqueue(dev->workqueue);
> >  err_v4l2_register:
> >  	v4l2_device_unregister(&dev->v4l2_dev);
> > @@ -3136,6 +3138,7 @@ static int coda_remove(struct platform_device *pdev)
> >  	}
> >  	if (dev->m2m_dev)
> >  		v4l2_m2m_release(dev->m2m_dev);
> > +	pm_runtime_put_noidle(&pdev->dev);
> 
> I think this is incorrect. There is one pm_runtime_get_noresume() in
> coda_probe(), and one pm_runtime_put_sync() in coda_fw_callback().
> By the time coda_remove() is called, balance is already restored.
> 
> regards
> Philipp

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

end of thread, other threads:[~2020-05-25 12:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23 10:03 [PATCH] media: coda: Fix runtime PM imbalance in coda_probe Dinghao Liu
2020-05-25 12:38 ` Philipp Zabel
2020-05-25 12:52   ` dinghao.liu

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