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 2/2] iio: gyro: fxs210002c: Use guard(mutex)() for remaining simple cases.
Date: Mon, 26 Oct 2026 03:20:51 +0000 [thread overview]
Message-ID: <20261026032051.1004536-3-jic23@kernel.org> (raw)
In-Reply-To: <20261026032051.1004536-1-jic23@kernel.org>
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
With the exception of the more complex flow in the trigger handler,
all uses of the data->lock are switched to using guard()()
simplifying various error flows.
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/gyro/fxas21002c_core.c | 71 ++++++++++--------------------
1 file changed, 24 insertions(+), 47 deletions(-)
diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
index fe1ac3e841dc..b6e6db4ad94c 100644
--- a/drivers/iio/gyro/fxas21002c_core.c
+++ b/drivers/iio/gyro/fxas21002c_core.c
@@ -341,28 +341,21 @@ static int fxas21002c_write(struct fxas21002c_data *data,
int actual_mode;
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
actual_mode = fxas21002c_mode_get(data);
- if (actual_mode < 0) {
- ret = actual_mode;
- goto out_unlock;
- }
+ if (actual_mode < 0)
+ return actual_mode;
ret = fxas21002c_mode_set(data, FXAS21002C_MODE_READY);
if (ret < 0)
- goto out_unlock;
+ return ret;
ret = regmap_field_write(data->regmap_fields[field], bits);
if (ret < 0)
- goto out_unlock;
-
- ret = fxas21002c_mode_set(data, data->prev_mode);
-
-out_unlock:
- mutex_unlock(&data->lock);
+ return ret;
- return ret;
+ return fxas21002c_mode_set(data, data->prev_mode);
}
static int fxas21002c_temp_get(struct fxas21002c_data *data, int *val)
@@ -420,19 +413,15 @@ static int fxas21002c_odr_get(struct fxas21002c_data *data, int *odr)
unsigned int odr_bits;
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
+
ret = regmap_field_read(data->regmap_fields[F_DR], &odr_bits);
if (ret < 0)
- goto data_unlock;
+ return ret;
*odr = fxas21002c_odr_hz_from_value(data, odr_bits);
- ret = IIO_VAL_INT;
-
-data_unlock:
- mutex_unlock(&data->lock);
-
- return ret;
+ return IIO_VAL_INT;
}
static int fxas21002c_odr_set(struct fxas21002c_data *data, int odr)
@@ -451,19 +440,15 @@ static int fxas21002c_lpf_get(struct fxas21002c_data *data, int *val2)
unsigned int bw_bits;
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
+
ret = regmap_field_read(data->regmap_fields[F_BW], &bw_bits);
if (ret < 0)
- goto data_unlock;
+ return ret;
*val2 = fxas21002c_lpf_bw_from_value(data, bw_bits) * 10000;
- ret = IIO_VAL_INT_PLUS_MICRO;
-
-data_unlock:
- mutex_unlock(&data->lock);
-
- return ret;
+ return IIO_VAL_INT_PLUS_MICRO;
}
static int fxas21002c_lpf_set(struct fxas21002c_data *data, int bw)
@@ -495,19 +480,15 @@ static int fxas21002c_hpf_get(struct fxas21002c_data *data, int *val2)
unsigned int sel_bits;
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
+
ret = regmap_field_read(data->regmap_fields[F_SEL], &sel_bits);
if (ret < 0)
- goto data_unlock;
+ return ret;
*val2 = fxas21002c_hpf_sel_from_value(data, sel_bits);
- ret = IIO_VAL_INT_PLUS_MICRO;
-
-data_unlock:
- mutex_unlock(&data->lock);
-
- return ret;
+ return IIO_VAL_INT_PLUS_MICRO;
}
static int fxas21002c_hpf_set(struct fxas21002c_data *data, int sel)
@@ -527,23 +508,19 @@ static int fxas21002c_scale_get(struct fxas21002c_data *data, int *val)
int scale;
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
+
ret = regmap_field_read(data->regmap_fields[F_FS], &fs_bits);
if (ret < 0)
- goto data_unlock;
+ return ret;
scale = fxas21002c_range_fs_from_value(data, fs_bits);
- if (scale < 0) {
- ret = scale;
- goto data_unlock;
- }
+ if (scale < 0)
+ return scale;
*val = scale;
-data_unlock:
- mutex_unlock(&data->lock);
-
- return ret;
+ return 0;
}
static int fxas21002c_scale_set(struct fxas21002c_data *data, int range)
--
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 ` [PATCH v3 1/2] iio: gyro: fxas21002c: Discard pm_runtime_put_autosuspend() return values Jonathan Cameron
2026-10-26 9:54 ` Andy Shevchenko
2026-10-26 17:42 ` Brian Norris
2026-10-26 3:20 ` Jonathan Cameron [this message]
2026-10-26 9:56 ` [PATCH v3 2/2] iio: gyro: fxs210002c: Use guard(mutex)() for remaining simple cases 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-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.