mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Brian Norris <briannorris@chromium.org>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Ulf Hansson" <ulfh@kernel.org>,
	linux-pm@vger.kernel.org, "Andy Shevchenko" <andy@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 13/17] iio: light: apds9960: Discard pm_runtime_put_autosuspend() return values
Date: Mon, 2 Nov 2026 01:27:33 +0000	[thread overview]
Message-ID: <20261102012733.435bdc94@jic23-hlaptop> (raw)
In-Reply-To: <20261021165858.v2.13.Ic0c3be7c36a602e32c04628d5ae5692556742fa8@changeid>

On Wed, 21 Oct 2026 16:57:14 -0700
Brian Norris <briannorris@chromium.org> wrote:

> This driver propagates the return value of pm_runtime_put_autosuspend(),
> which is not particularly useful.
> 
> Returning an error code from pm_runtime_put_autosuspend() merely means
> that it has not queued up a timer or work item to check whether or not
> the device can be suspended and there are many perfectly valid
> situations in which that can happen, like after writing "on" to the
> device's runtime PM "control" attribute in sysfs for one example.
> 
> For this reason, modify this driver to simply discard the
> pm_runtime_put_autosuspend() return value. Inline the "off" helper, as
> it's trivial now, and rename to apds9960_power_on().
> 
> This will facilitate a planned change of the
> pm_runtime_put_autosuspend() return type to void in the future, similar
> to commit 3afd8df02433 ("PM: runtime: Change pm_runtime_put() return
> type to void").
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>

I took a look at this one and the current code is a complete mess.

I'm going to apply what you have here as a step in the right direction
simply because I can't see a quick path to fixing it properly.

If anyone wants a fun project then unwinding the mess in here would
be a good place to start.

Anyhow, applied this one.

thanks,

Jonathan

> ---
> I'm not sure if apds9960_write_event_config()'s existing logic is
> correct, but I don't want to mess with it.
> 
> Changes in v2:
>  * Split iio patch into per-driver patches
>  * Inline the put() helper
> 
>  drivers/iio/light/apds9960.c | 48 ++++++++++++++----------------------
>  1 file changed, 18 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/iio/light/apds9960.c b/drivers/iio/light/apds9960.c
> index afe520de60e2..0e084ffba1a6 100644
> --- a/drivers/iio/light/apds9960.c
> +++ b/drivers/iio/light/apds9960.c
> @@ -476,38 +476,23 @@ static int apds9960_set_als_gain(struct apds9960_data *data, int val)
>  	return ret;
>  }
>  
> -#ifdef CONFIG_PM
> -static int apds9960_set_power_state(struct apds9960_data *data, bool on)
> +static void apds9960_power_on(struct apds9960_data *data)
>  {
>  	struct device *dev = &data->client->dev;
> -	int ret = 0;
> +	int suspended;
>  
>  	mutex_lock(&data->lock);
>  
> -	if (on) {
> -		int suspended;
> -
> -		suspended = pm_runtime_suspended(dev);
> -		ret = pm_runtime_get_sync(dev);
> +	suspended = pm_runtime_suspended(dev);
> +	pm_runtime_get_sync(dev);
>  
> -		/* Allow one integration cycle before allowing a reading */
> -		if (suspended)
> -			usleep_range(data->als_adc_int_us,
> -				     APDS9960_MAX_INT_TIME_IN_US);
> -	} else {
> -		ret = pm_runtime_put_autosuspend(dev);
> -	}
> +	/* Allow one integration cycle before allowing a reading */
> +	if (suspended)
> +		usleep_range(data->als_adc_int_us,
> +			     APDS9960_MAX_INT_TIME_IN_US);
>  
>  	mutex_unlock(&data->lock);
> -
> -	return ret;
>  }
> -#else
> -static int apds9960_set_power_state(struct apds9960_data *data, bool on)
> -{
> -	return 0;
> -}
> -#endif
>  
>  static int apds9960_read_raw(struct iio_dev *indio_dev,
>  			     struct iio_chan_spec const *chan,
> @@ -522,7 +507,7 @@ static int apds9960_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		apds9960_set_power_state(data, true);
> +		apds9960_power_on(data);
>  		switch (chan->type) {
>  		case IIO_PROXIMITY:
>  			ret = regmap_read(data->regmap, chan->address, val);
> @@ -540,7 +525,7 @@ static int apds9960_read_raw(struct iio_dev *indio_dev,
>  		default:
>  			ret = -EINVAL;
>  		}
> -		apds9960_set_power_state(data, false);
> +		pm_runtime_put_autosuspend(&data->client->dev);
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
>  		/* RGB + ALS sensors only have integration time */
> @@ -767,7 +752,6 @@ static int apds9960_write_event_config(struct iio_dev *indio_dev,
>  		if (ret)
>  			return ret;
>  		data->pxs_int = state;
> -		apds9960_set_power_state(data, state);
>  		break;
>  	case IIO_INTENSITY:
>  		if (data->als_int == state)
> @@ -777,12 +761,16 @@ static int apds9960_write_event_config(struct iio_dev *indio_dev,
>  		if (ret)
>  			return ret;
>  		data->als_int = state;
> -		apds9960_set_power_state(data, state);
>  		break;
>  	default:
>  		return -EINVAL;
>  	}
>  
> +	if (state)
> +		apds9960_power_on(data);
> +	else
> +		pm_runtime_put_autosuspend(&data->client->dev);
> +
>  	return 0;
>  }
>  
> @@ -1078,7 +1066,7 @@ static int apds9960_probe(struct i2c_client *client)
>  	pm_runtime_set_autosuspend_delay(&client->dev, 5000);
>  	pm_runtime_use_autosuspend(&client->dev);
>  
> -	apds9960_set_power_state(data, true);
> +	apds9960_power_on(data);
>  
>  	ret = apds9960_regfield_init(data);
>  	if (ret)
> @@ -1105,12 +1093,12 @@ static int apds9960_probe(struct i2c_client *client)
>  	if (ret)
>  		goto error_power_down;
>  
> -	apds9960_set_power_state(data, false);
> +	pm_runtime_put_autosuspend(&client->dev);
>  
>  	return 0;
>  
>  error_power_down:
> -	apds9960_set_power_state(data, false);
> +	pm_runtime_put_autosuspend(&client->dev);
>  
>  	return ret;
>  }


  reply	other threads:[~2026-11-02  1:27 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 23:57 [PATCH v2 00/17] iio: Stop looking at pm_runtime_put_autosuspend() return codes Brian Norris
2026-10-21 23:57 ` [PATCH v2 01/17] iio: accel: fxls8962af: Discard pm_runtime_put_autosuspend() return values Brian Norris
2026-10-22  6:53   ` Andy Shevchenko
2026-10-22 17:51     ` Brian Norris
2026-10-23  3:29       ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 02/17] iio: accel: kxcjk-1013: " Brian Norris
2026-10-22  6:58   ` Andy Shevchenko
2026-10-23  3:36   ` Jonathan Cameron
2026-10-23 16:43     ` Brian Norris
2026-10-21 23:57 ` [PATCH v2 03/17] iio: accel: mma8452: " Brian Norris
2026-10-22  6:59   ` Andy Shevchenko
2026-10-21 23:57 ` [PATCH v2 04/17] iio: accel: mma955x: " Brian Norris
2026-11-02  1:58   ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 05/17] iio: accel: bmc150: " Brian Norris
2026-10-21 23:57 ` [PATCH v2 06/17] iio: adc: rcar-gyroadc: " Brian Norris
2026-10-22  9:23   ` Geert Uytterhoeven
2026-10-26  3:28     ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 07/17] iio: adc: ti-ads1015: " Brian Norris
2026-10-26  3:27   ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 08/17] iio: chemical: atlas-sensor: " Brian Norris
2026-10-26  3:25   ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 09/17] iio: hid-sensors: " Brian Norris
2026-11-02  1:52   ` Jonathan Cameron
2026-11-02 16:55     ` srinivas pandruvada
2026-11-02 22:05       ` Jonathan Cameron
2026-11-02 22:35         ` srinivas pandruvada
2026-10-21 23:57 ` [PATCH v2 10/17] iio: gyro: bmg160: " Brian Norris
2026-10-21 23:57 ` [PATCH v2 11/17] iio: gyro: fxas21002c: " Brian Norris
2026-10-26  3:21   ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 12/17] iio: imu: kmx61: " Brian Norris
2026-10-26  1:13   ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 13/17] iio: light: apds9960: " Brian Norris
2026-11-02  1:27   ` Jonathan Cameron [this message]
2026-10-21 23:57 ` [PATCH v2 14/17] iio: light: pa12203001: " Brian Norris
2026-10-26  1:08   ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 15/17] iio: light: rpr0521: " Brian Norris
2026-10-26  0:58   ` Jonathan Cameron
2026-10-21 23:57 ` [PATCH v2 16/17] iio: light: tsl2583: " Brian Norris
2026-10-26  0:55   ` Jonathan Cameron
2026-10-26 17:59     ` Brian Norris
2026-10-26 18:42       ` Andy Shevchenko
2026-10-21 23:57 ` [PATCH v2 17/17] iio: light: us5182d: " Brian Norris
2026-10-26  0:53   ` Jonathan Cameron
2026-10-22  7:01 ` [PATCH v2 00/17] iio: Stop looking at pm_runtime_put_autosuspend() return codes Andy Shevchenko
2026-10-22 17:47   ` Brian Norris
2026-10-23  6:54     ` Andy Shevchenko
2026-10-23 16:43       ` Brian Norris
2026-10-26 10:09         ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261102012733.435bdc94@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=briannorris@chromium.org \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=rafael@kernel.org \
    --cc=ulfh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®