From: Brian Norris <briannorris@chromium.org>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, "Nuno Sá" <nuno.sa@analog.com>,
linux-pm@vger.kernel.org, "Andy Shevchenko" <andy@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
linux-kernel@vger.kernel.org,
"Jonathan Cameron" <jonathan.cameron@oss.qualcomm.com>
Subject: Re: [PATCH v3] iio: gyro: bmg160: Discard pm_runtime_put_autosuspend() return values
Date: Mon, 2 Nov 2026 13:15:59 -0800 [thread overview]
Message-ID: <auj9j3sbYa4sVoil@google.com> (raw)
In-Reply-To: <20261102014830.679216-1-jic23@kernel.org>
Hi Jonathan,
On Mon, Nov 02, 2026 at 01:48:30AM +0000, Jonathan Cameron wrote:
> From: Brian Norris <briannorris@chromium.org>
>
> 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, and inline
> bmg160_set_power_state() now that it behaves the same with and without
> CONFIG_PM and is otherwise trivial.
>
> Now the return value of the cleanup is ignored, also switch various
> paths to use PM_RUNTIEM_ACQUIRE_AUTOSUSPEND() in conjunction
> with guard(mutex)() futher simplifying the code.
>
> While at it, I notice that bmg160_write_event_config() and
> bmg160_data_rdy_trigger_set_state() mismanage the runtime PM reference
> count intentionally, relying on racy autosuspend behavior for
> correctness. I refactor this to manage refcounts properly instead.
> I use guard() for the mutex, to make this less error prone.
>
> Additionally, bmg160_write_raw() had one error path where a
> pm_runtime_resume_and_get() failure would also drop a runtime PM
> refcount (pm_runtime_put_autosuspend()), which potentially leads to
> underflow. I fix that.
>
> 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>
> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> ---
> I'm continuing to nibble away at Brian's series applying some of the
> additional changes Andy asked for (that Brian quite reasonably stated
> were beyond what he was going to take on!) Just this one today.
>
> v3: Make use of ACQUIRE magic in various paths as enabled
> by dropping the return value.
>
> With this posted, I'll mark it changes requested in patchwork.
>
> https://patchwork.kernel.org/project/linux-iio/patch/20261021165858.v2.10.I5918e916cbe48281c13e5734733a3281e7be8841@changeid/
>
> ---
> drivers/iio/gyro/bmg160_core.c | 237 +++++++++++++--------------------
> 1 file changed, 94 insertions(+), 143 deletions(-)
>
> diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
> index b007f46d3fd6..a48e01ecc367 100644
> --- a/drivers/iio/gyro/bmg160_core.c
> +++ b/drivers/iio/gyro/bmg160_core.c
> @@ -759,42 +700,37 @@ static int bmg160_write_event_config(struct iio_dev *indio_dev,
> bool state)
> {
> struct bmg160_data *data = iio_priv(indio_dev);
> + struct device *dev = regmap_get_device(data->regmap);
> int ret;
>
> if (state && data->ev_enable_state)
> return 0;
>
> - mutex_lock(&data->mutex);
> + guard(mutex)(&data->mutex);
>
> if (!state && data->motion_trigger_on) {
> data->ev_enable_state = 0;
> - mutex_unlock(&data->mutex);
> return 0;
> }
> - /*
> - * We will expect the enable and disable to do operation
> - * in reverse order. This will happen here anyway as our
> - * resume operation uses sync mode runtime pm calls, the
> - * suspend operation will be delayed by autosuspend delay
> - * So the disable operation will still happen in reverse of
> - * enable operation. When runtime pm is disabled the mode
> - * is always on so sequence doesn't matter
> - */
> - ret = bmg160_set_power_state(data, state);
> - if (ret < 0) {
> - mutex_unlock(&data->mutex);
> - return ret;
> - }
> + if (state) {
> + ret = pm_runtime_resume_and_get(dev);
> + if (ret < 0) {
> + dev_err(dev, "failed to resume: %d\n", ret);
> + return ret;
> + }
>
> - ret = bmg160_setup_any_motion_interrupt(data, state);
> - if (ret < 0) {
> - bmg160_set_power_state(data, false);
> - mutex_unlock(&data->mutex);
> - return ret;
> - }
> + ret = bmg160_setup_any_motion_interrupt(data, true);
> + if (ret < 0) {
> + pm_runtime_put_autosuspend(dev);
> + return ret;
> + }
> + } else {
> + ret = bmg160_setup_any_motion_interrupt(data, false);
> + if (ret < 0)
> + return ret;
>
> - data->ev_enable_state = state;
This is an unexpected (to me) delta vs v2: you've stopped setting
data->ev_enable_state here. I think that's a regression.
This is also one reason I think it's unwise to make so many changes
together here. One person's "churn" (to apply several patches to similar
code) is another person's "hard to review / easy to make mistakes".
Brian
> - mutex_unlock(&data->mutex);
> + pm_runtime_put_autosuspend(dev);
> + }
>
> return 0;
> }
prev parent reply other threads:[~2026-11-02 21:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 1:48 [PATCH v3] iio: gyro: bmg160: Discard pm_runtime_put_autosuspend() return values Jonathan Cameron
2026-11-02 21:15 ` Brian Norris [this message]
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=auj9j3sbYa4sVoil@google.com \
--to=briannorris@chromium.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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