diff mbox series

[03/28] iio: light: tsl2583: Balance runtime pm + use pm_runtime_resume_and_get()

Message ID 20210509113354.660190-4-jic23@kernel.org (mailing list archive)
State New, archived
Headers show
Series IIO: Runtime PM related cleanups. | expand

Commit Message

Jonathan Cameron May 9, 2021, 11:33 a.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Error paths in read_raw() and write_raw() callbacks failed to perform and
type of runtime pm put().  Remove called pm_runtime_put_noidle()
but there is no equivalent get (this is safe because the reference
count is protected against going below zero, but it is misleading.

Whilst here use pm_runtime_resume_and_get() to replace boilerplate.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Brian Masney <masneyb@onstation.org>
---
 drivers/iio/light/tsl2583.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Brian Masney May 10, 2021, 10:46 a.m. UTC | #1
On Sun, May 09, 2021 at 12:33:29PM +0100, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> Error paths in read_raw() and write_raw() callbacks failed to perform and
> type of runtime pm put().  Remove called pm_runtime_put_noidle()
> but there is no equivalent get (this is safe because the reference
> count is protected against going below zero, but it is misleading.
> 
> Whilst here use pm_runtime_resume_and_get() to replace boilerplate.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Brian Masney <masneyb@onstation.org>

Reviewed-by: Brian Masney <masneyb@onstation.org>
Mauro Carvalho Chehab May 12, 2021, 1:35 p.m. UTC | #2
Em Sun,  9 May 2021 12:33:29 +0100
Jonathan Cameron <jic23@kernel.org> escreveu:

> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> Error paths in read_raw() and write_raw() callbacks failed to perform and
> type of runtime pm put().  Remove called pm_runtime_put_noidle()
> but there is no equivalent get (this is safe because the reference
> count is protected against going below zero, but it is misleading.
> 
> Whilst here use pm_runtime_resume_and_get() to replace boilerplate.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Brian Masney <masneyb@onstation.org>

LGTM.

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


> ---
>  drivers/iio/light/tsl2583.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
> index 0f787bfc88fc..1f4ad4047a86 100644
> --- a/drivers/iio/light/tsl2583.c
> +++ b/drivers/iio/light/tsl2583.c
> @@ -636,9 +636,7 @@ static int tsl2583_set_pm_runtime_busy(struct tsl2583_chip *chip, bool on)
>  	int ret;
>  
>  	if (on) {
> -		ret = pm_runtime_get_sync(&chip->client->dev);
> -		if (ret < 0)
> -			pm_runtime_put_noidle(&chip->client->dev);
> +		ret = pm_runtime_resume_and_get(&chip->client->dev);
>  	} else {
>  		pm_runtime_mark_last_busy(&chip->client->dev);
>  		ret = pm_runtime_put_autosuspend(&chip->client->dev);
> @@ -721,8 +719,10 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
>  read_done:
>  	mutex_unlock(&chip->als_mutex);
>  
> -	if (ret < 0)
> +	if (ret < 0) {
> +		tsl2583_set_pm_runtime_busy(chip, false);
>  		return ret;
> +	}
>  
>  	/*
>  	 * Preserve the ret variable if the call to
> @@ -783,8 +783,10 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
>  
>  	mutex_unlock(&chip->als_mutex);
>  
> -	if (ret < 0)
> +	if (ret < 0) {
> +		tsl2583_set_pm_runtime_busy(chip, false);
>  		return ret;
> +	}
>  
>  	ret = tsl2583_set_pm_runtime_busy(chip, false);
>  	if (ret < 0)
> @@ -872,7 +874,6 @@ static int tsl2583_remove(struct i2c_client *client)
>  
>  	pm_runtime_disable(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
> -	pm_runtime_put_noidle(&client->dev);
>  
>  	return tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
>  }



Thanks,
Mauro
Jonathan Cameron May 13, 2021, 4:39 p.m. UTC | #3
On Mon, 10 May 2021 06:46:01 -0400
Brian Masney <masneyb@onstation.org> wrote:

> On Sun, May 09, 2021 at 12:33:29PM +0100, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > 
> > Error paths in read_raw() and write_raw() callbacks failed to perform and
> > type of runtime pm put().  Remove called pm_runtime_put_noidle()
> > but there is no equivalent get (this is safe because the reference
> > count is protected against going below zero, but it is misleading.
> > 
> > Whilst here use pm_runtime_resume_and_get() to replace boilerplate.
> > 
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Brian Masney <masneyb@onstation.org>  
> 
> Reviewed-by: Brian Masney <masneyb@onstation.org>
> 
Applied.  Thanks,

Jonathan
diff mbox series

Patch

diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
index 0f787bfc88fc..1f4ad4047a86 100644
--- a/drivers/iio/light/tsl2583.c
+++ b/drivers/iio/light/tsl2583.c
@@ -636,9 +636,7 @@  static int tsl2583_set_pm_runtime_busy(struct tsl2583_chip *chip, bool on)
 	int ret;
 
 	if (on) {
-		ret = pm_runtime_get_sync(&chip->client->dev);
-		if (ret < 0)
-			pm_runtime_put_noidle(&chip->client->dev);
+		ret = pm_runtime_resume_and_get(&chip->client->dev);
 	} else {
 		pm_runtime_mark_last_busy(&chip->client->dev);
 		ret = pm_runtime_put_autosuspend(&chip->client->dev);
@@ -721,8 +719,10 @@  static int tsl2583_read_raw(struct iio_dev *indio_dev,
 read_done:
 	mutex_unlock(&chip->als_mutex);
 
-	if (ret < 0)
+	if (ret < 0) {
+		tsl2583_set_pm_runtime_busy(chip, false);
 		return ret;
+	}
 
 	/*
 	 * Preserve the ret variable if the call to
@@ -783,8 +783,10 @@  static int tsl2583_write_raw(struct iio_dev *indio_dev,
 
 	mutex_unlock(&chip->als_mutex);
 
-	if (ret < 0)
+	if (ret < 0) {
+		tsl2583_set_pm_runtime_busy(chip, false);
 		return ret;
+	}
 
 	ret = tsl2583_set_pm_runtime_busy(chip, false);
 	if (ret < 0)
@@ -872,7 +874,6 @@  static int tsl2583_remove(struct i2c_client *client)
 
 	pm_runtime_disable(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
-	pm_runtime_put_noidle(&client->dev);
 
 	return tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
 }