linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: imx: imx7-mipi-csis: Fix runtime PM imbalance in mipi_csis_s_stream
@ 2021-04-08  9:08 Dinghao Liu
  2021-04-08 13:57 ` Rui Miguel Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2021-04-08  9:08 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, linux-media, linux-staging, linux-arm-kernel,
	linux-kernel

When v4l2_subdev_call() fails, a pairing PM usage counter
decrement is needed to keep the counter balanced. It's the
same for the following error paths in case 'enable' is on.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index a01a7364b4b9..2a3fff231a40 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -627,21 +627,26 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 			return ret;
 		}
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
-		if (ret < 0)
+		if (ret < 0) {
+			pm_runtime_put_noidle(&state->pdev->dev);
 			return ret;
+		}
 	}
 
 	mutex_lock(&state->lock);
 	if (enable) {
 		if (state->flags & ST_SUSPENDED) {
 			ret = -EBUSY;
+			pm_runtime_put_noidle(&state->pdev->dev);
 			goto unlock;
 		}
 
 		mipi_csis_start_stream(state);
 		ret = v4l2_subdev_call(state->src_sd, video, s_stream, 1);
-		if (ret < 0)
+		if (ret < 0) {
+			pm_runtime_put_noidle(&state->pdev->dev);
 			goto unlock;
+		}
 
 		mipi_csis_log_counters(state, true);
 
-- 
2.17.1


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

* Re: [PATCH] media: imx: imx7-mipi-csis: Fix runtime PM imbalance in mipi_csis_s_stream
  2021-04-08  9:08 [PATCH] media: imx: imx7-mipi-csis: Fix runtime PM imbalance in mipi_csis_s_stream Dinghao Liu
@ 2021-04-08 13:57 ` Rui Miguel Silva
  2021-04-09  7:59   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Rui Miguel Silva @ 2021-04-08 13:57 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: kjlu, Steve Longerbeam, Philipp Zabel, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	linux-media, linux-staging, linux-arm-kernel, linux-kernel

Hi Liu,
Thanks for your patch.

On Thu, Apr 08, 2021 at 05:08:27PM +0800, Dinghao Liu wrote:
> When v4l2_subdev_call() fails, a pairing PM usage counter
> decrement is needed to keep the counter balanced. It's the
> same for the following error paths in case 'enable' is on.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/staging/media/imx/imx7-mipi-csis.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> index a01a7364b4b9..2a3fff231a40 100644
> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> @@ -627,21 +627,26 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
>  			return ret;
>  		}
>  		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			pm_runtime_put_noidle(&state->pdev->dev);

I think here we should go completely pm_runtime_put to call the
mipi_csis_pm_suspend down the line, right?

>  			return ret;
> +		}
>  	}
>  
>  	mutex_lock(&state->lock);
>  	if (enable) {
>  		if (state->flags & ST_SUSPENDED) {
>  			ret = -EBUSY;
> +			pm_runtime_put_noidle(&state->pdev->dev);

since we are in ST_SUSPENDED state, for sure the pm counter was
already 0.

>  			goto unlock;
>  		}
>  
>  		mipi_csis_start_stream(state);
>  		ret = v4l2_subdev_call(state->src_sd, video, s_stream, 1);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			pm_runtime_put_noidle(&state->pdev->dev);

here also we need the pm_runtime_put, maybe just changing the unlock
tag bellow from:
    if (!enable)
        pm_runtime_put(&state->pdev->dev);

to 
    if (!enable || (ret < 0))
        pm_runtime_put(&state->pdev->dev);

will not hurt the first case and will complete the suspend routine
afterward in the second case.

------
Cheers,
     Rui
>  			goto unlock;
> +		}
>  
>  		mipi_csis_log_counters(state, true);
>  
> -- 
> 2.17.1
> 
> 

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

* Re: Re: [PATCH] media: imx: imx7-mipi-csis: Fix runtime PM imbalance in mipi_csis_s_stream
  2021-04-08 13:57 ` Rui Miguel Silva
@ 2021-04-09  7:59   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2021-04-09  7:59 UTC (permalink / raw)
  To: Rui Miguel Silva
  Cc: kjlu, Steve Longerbeam, Philipp Zabel, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	linux-media, linux-staging, linux-arm-kernel, linux-kernel

> Hi Liu,
> Thanks for your patch.
> 
> On Thu, Apr 08, 2021 at 05:08:27PM +0800, Dinghao Liu wrote:
> > When v4l2_subdev_call() fails, a pairing PM usage counter
> > decrement is needed to keep the counter balanced. It's the
> > same for the following error paths in case 'enable' is on.
> > 
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/staging/media/imx/imx7-mipi-csis.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> > index a01a7364b4b9..2a3fff231a40 100644
> > --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> > +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> > @@ -627,21 +627,26 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
> >  			return ret;
> >  		}
> >  		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
> > -		if (ret < 0)
> > +		if (ret < 0) {
> > +			pm_runtime_put_noidle(&state->pdev->dev);
> 
> I think here we should go completely pm_runtime_put to call the
> mipi_csis_pm_suspend down the line, right?
> 
> >  			return ret;
> > +		}
> >  	}
> >  
> >  	mutex_lock(&state->lock);
> >  	if (enable) {
> >  		if (state->flags & ST_SUSPENDED) {
> >  			ret = -EBUSY;
> > +			pm_runtime_put_noidle(&state->pdev->dev);
> 
> since we are in ST_SUSPENDED state, for sure the pm counter was
> already 0.
> 
> >  			goto unlock;
> >  		}
> >  
> >  		mipi_csis_start_stream(state);
> >  		ret = v4l2_subdev_call(state->src_sd, video, s_stream, 1);
> > -		if (ret < 0)
> > +		if (ret < 0) {
> > +			pm_runtime_put_noidle(&state->pdev->dev);
> 
> here also we need the pm_runtime_put, maybe just changing the unlock
> tag bellow from:
>     if (!enable)
>         pm_runtime_put(&state->pdev->dev);
> 
> to 
>     if (!enable || (ret < 0))
>         pm_runtime_put(&state->pdev->dev);
> 
> will not hurt the first case and will complete the suspend routine
> afterward in the second case.
> 

This is much clearer, thanks! I will fix this and send a new patch soon.

Regards,
Dinghao

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

end of thread, other threads:[~2021-04-09  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08  9:08 [PATCH] media: imx: imx7-mipi-csis: Fix runtime PM imbalance in mipi_csis_s_stream Dinghao Liu
2021-04-08 13:57 ` Rui Miguel Silva
2021-04-09  7:59   ` 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).