diff mbox series

[v2,6/6] iio: pressure: icp10100: Balance runtime pm + use pm_runtime_resume_and_get()

Message ID 20210516162103.1332291-7-jic23@kernel.org (mailing list archive)
State Accepted
Headers show
Series IIO: Runtime PM related cleanups. | expand

Commit Message

Jonathan Cameron May 16, 2021, 4:21 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

The devm_ handled runtime pm disable calls pm_runtime_put_sync_suspend()
which isn't balancing a matching get call.  It isn't a bug as such,
because the runtime pm core doesn't decrement the reference count below
zero, but it is missleading so let's drop it.

Using pm_runtime_resume_and_get() new call makes it easy to handle
failures in resume as it doesn't hold a reference count if it exits
with an error.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
 drivers/iio/pressure/icp10100.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Mauro Carvalho Chehab June 16, 2021, 7:16 a.m. UTC | #1
Em Sun, 16 May 2021 17:21:03 +0100
Jonathan Cameron <jic23@kernel.org> escreveu:

> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> The devm_ handled runtime pm disable calls pm_runtime_put_sync_suspend()
> which isn't balancing a matching get call.  It isn't a bug as such,
> because the runtime pm core doesn't decrement the reference count below
> zero, but it is missleading so let's drop it.
> 
> Using pm_runtime_resume_and_get() new call makes it easy to handle
> failures in resume as it doesn't hold a reference count if it exits
> with an error.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>

LGTM.

Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

> ---
>  drivers/iio/pressure/icp10100.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/pressure/icp10100.c b/drivers/iio/pressure/icp10100.c
> index 48759fc4bf18..af4621eaa6b5 100644
> --- a/drivers/iio/pressure/icp10100.c
> +++ b/drivers/iio/pressure/icp10100.c
> @@ -250,7 +250,9 @@ static int icp10100_get_measures(struct icp10100_state *st,
>  	__be16 measures[3];
>  	int ret;
>  
> -	pm_runtime_get_sync(&st->client->dev);
> +	ret = pm_runtime_resume_and_get(&st->client->dev);
> +	if (ret < 0)
> +		return ret;
>  
>  	mutex_lock(&st->lock);
>  	cmd = &icp10100_cmd_measure[st->mode];
> @@ -525,7 +527,6 @@ static void icp10100_pm_disable(void *data)
>  {
>  	struct device *dev = data;
>  
> -	pm_runtime_put_sync_suspend(dev);
>  	pm_runtime_disable(dev);
>  }
>  



Thanks,
Mauro
Jonathan Cameron June 16, 2021, 12:56 p.m. UTC | #2
On Wed, 16 Jun 2021 09:16:38 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> Em Sun, 16 May 2021 17:21:03 +0100
> Jonathan Cameron <jic23@kernel.org> escreveu:
> 
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > 
> > The devm_ handled runtime pm disable calls pm_runtime_put_sync_suspend()
> > which isn't balancing a matching get call.  It isn't a bug as such,
> > because the runtime pm core doesn't decrement the reference count below
> > zero, but it is missleading so let's drop it.
> > 
> > Using pm_runtime_resume_and_get() new call makes it easy to handle
> > failures in resume as it doesn't hold a reference count if it exits
> > with an error.
> > 
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>  
> 
> LGTM.
> 
> Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Applied.

> 
> > ---
> >  drivers/iio/pressure/icp10100.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/pressure/icp10100.c b/drivers/iio/pressure/icp10100.c
> > index 48759fc4bf18..af4621eaa6b5 100644
> > --- a/drivers/iio/pressure/icp10100.c
> > +++ b/drivers/iio/pressure/icp10100.c
> > @@ -250,7 +250,9 @@ static int icp10100_get_measures(struct icp10100_state *st,
> >  	__be16 measures[3];
> >  	int ret;
> >  
> > -	pm_runtime_get_sync(&st->client->dev);
> > +	ret = pm_runtime_resume_and_get(&st->client->dev);
> > +	if (ret < 0)
> > +		return ret;
> >  
> >  	mutex_lock(&st->lock);
> >  	cmd = &icp10100_cmd_measure[st->mode];
> > @@ -525,7 +527,6 @@ static void icp10100_pm_disable(void *data)
> >  {
> >  	struct device *dev = data;
> >  
> > -	pm_runtime_put_sync_suspend(dev);
> >  	pm_runtime_disable(dev);
> >  }
> >    
> 
> 
> 
> Thanks,
> Mauro
diff mbox series

Patch

diff --git a/drivers/iio/pressure/icp10100.c b/drivers/iio/pressure/icp10100.c
index 48759fc4bf18..af4621eaa6b5 100644
--- a/drivers/iio/pressure/icp10100.c
+++ b/drivers/iio/pressure/icp10100.c
@@ -250,7 +250,9 @@  static int icp10100_get_measures(struct icp10100_state *st,
 	__be16 measures[3];
 	int ret;
 
-	pm_runtime_get_sync(&st->client->dev);
+	ret = pm_runtime_resume_and_get(&st->client->dev);
+	if (ret < 0)
+		return ret;
 
 	mutex_lock(&st->lock);
 	cmd = &icp10100_cmd_measure[st->mode];
@@ -525,7 +527,6 @@  static void icp10100_pm_disable(void *data)
 {
 	struct device *dev = data;
 
-	pm_runtime_put_sync_suspend(dev);
 	pm_runtime_disable(dev);
 }