From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org, "Nuno Sá" <nuno.sa@analog.com>
Cc: Brian Norris <briannorris@chromium.org>,
Andy Shevchenko <andy@kernel.org>,
David Lechner <dlechner@baylibre.com>,
Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Subject: [PATCH v3 1/2] iio: gyro: fxas21002c: Discard pm_runtime_put_autosuspend() return values
Date: Mon, 26 Oct 2026 03:20:50 +0000 [thread overview]
Message-ID: <20261026032051.1004536-2-jic23@kernel.org> (raw)
In-Reply-To: <20261026032051.1004536-1-jic23@kernel.org>
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.
With the driver modified to discard the pm_runtime_put_autosuspend()
return value, it becomes simple to use PM_RUNTIME_ACQUIRE() and
guard(mutex)() to simpify two locations. At the remaining location
simply dicusard the return value.
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>
---
Brian, given this tweaked your patch a fair bit, please let me know
if you are fine with this. Hopefully I didn't mess anything up!
---
drivers/iio/gyro/fxas21002c_core.c | 66 +++++++++---------------------
1 file changed, 20 insertions(+), 46 deletions(-)
diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
index a88670207cec..fe1ac3e841dc 100644
--- a/drivers/iio/gyro/fxas21002c_core.c
+++ b/drivers/iio/gyro/fxas21002c_core.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 Linaro Ltd.
*/
+#include <linux/cleanup.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/pm.h>
@@ -364,48 +365,28 @@ static int fxas21002c_write(struct fxas21002c_data *data,
return ret;
}
-static int fxas21002c_pm_get(struct fxas21002c_data *data)
-{
- return pm_runtime_resume_and_get(regmap_get_device(data->regmap));
-}
-
-static int fxas21002c_pm_put(struct fxas21002c_data *data)
-{
- struct device *dev = regmap_get_device(data->regmap);
-
- return pm_runtime_put_autosuspend(dev);
-}
-
static int fxas21002c_temp_get(struct fxas21002c_data *data, int *val)
{
struct device *dev = regmap_get_device(data->regmap);
unsigned int temp;
int ret;
- mutex_lock(&data->lock);
- ret = fxas21002c_pm_get(data);
- if (ret < 0)
- goto data_unlock;
+ guard(mutex)(&data->lock);
+
+ PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+ ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+ if (ret)
+ return ret;
ret = regmap_field_read(data->regmap_fields[F_TEMP], &temp);
if (ret < 0) {
dev_err(dev, "failed to read temp: %d\n", ret);
- fxas21002c_pm_put(data);
- goto data_unlock;
+ return ret;
}
*val = sign_extend32(temp, 7);
- ret = fxas21002c_pm_put(data);
- if (ret < 0)
- goto data_unlock;
-
- ret = IIO_VAL_INT;
-
-data_unlock:
- mutex_unlock(&data->lock);
-
- return ret;
+ return IIO_VAL_INT;
}
static int fxas21002c_axis_get(struct fxas21002c_data *data,
@@ -415,31 +396,23 @@ static int fxas21002c_axis_get(struct fxas21002c_data *data,
__be16 axis_be;
int ret;
- mutex_lock(&data->lock);
- ret = fxas21002c_pm_get(data);
- if (ret < 0)
- goto data_unlock;
+ guard(mutex)(&data->lock);
+
+ PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+ ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+ if (ret)
+ return ret;
ret = regmap_bulk_read(data->regmap, FXAS21002C_AXIS_TO_REG(index),
&axis_be, sizeof(axis_be));
if (ret < 0) {
dev_err(dev, "failed to read axis: %d: %d\n", index, ret);
- fxas21002c_pm_put(data);
- goto data_unlock;
+ return ret;
}
*val = sign_extend32(be16_to_cpu(axis_be), 15);
- ret = fxas21002c_pm_put(data);
- if (ret < 0)
- goto data_unlock;
-
- ret = IIO_VAL_INT;
-
-data_unlock:
- mutex_unlock(&data->lock);
-
- return ret;
+ return IIO_VAL_INT;
}
static int fxas21002c_odr_get(struct fxas21002c_data *data, int *odr)
@@ -725,10 +698,11 @@ static irqreturn_t fxas21002c_trigger_handler(int irq, void *p)
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct fxas21002c_data *data = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(data->regmap);
int ret;
mutex_lock(&data->lock);
- ret = fxas21002c_pm_get(data);
+ ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
goto out_unlock;
@@ -741,7 +715,7 @@ static irqreturn_t fxas21002c_trigger_handler(int irq, void *p)
data->timestamp);
out_pm_put:
- fxas21002c_pm_put(data);
+ pm_runtime_put_autosuspend(dev);
out_unlock:
mutex_unlock(&data->lock);
--
2.56.0
next prev parent reply other threads:[~2026-10-26 3:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 3:20 [PATCH v3 0/2] iio: fxas210002c: Discard pm_runtime_put_autosuspend() return and related cleanup Jonathan Cameron
2026-10-26 3:20 ` Jonathan Cameron [this message]
2026-10-26 9:54 ` [PATCH v3 1/2] iio: gyro: fxas21002c: Discard pm_runtime_put_autosuspend() return values Andy Shevchenko
2026-10-26 17:42 ` Brian Norris
2026-10-26 3:20 ` [PATCH v3 2/2] iio: gyro: fxs210002c: Use guard(mutex)() for remaining simple cases Jonathan Cameron
2026-10-26 9:56 ` Andy Shevchenko
2026-10-26 17:48 ` Brian Norris
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=20261026032051.1004536-2-jic23@kernel.org \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=briannorris@chromium.org \
--cc=dlechner@baylibre.com \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=linux-iio@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