[PATCH 1/4] iio: magnetometer: rm3100: Use scoped_guard() in rm3100_read_mag()

From: Maxwell Doose

Date: Mon Apr 27 2026 - 22:44:05 EST


Replace mutex_lock() and mutex_unlock() calls in rm3100_read_mag() with
the more modern scoped_guard(). This will help modernize the driver and
bring it up-to-date with modern available macros/functions.

While at it, remove the now unnecessary "unlock_return" goto and
directly return in if statements.

Signed-off-by: Maxwell Doose <m32285159@xxxxxxxxx>
---
drivers/iio/magnetometer/rm3100-core.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
index 2b2884425746..a2bf6e504a15 100644
--- a/drivers/iio/magnetometer/rm3100-core.c
+++ b/drivers/iio/magnetometer/rm3100-core.c
@@ -204,27 +204,23 @@ static int rm3100_read_mag(struct rm3100_data *data, int idx, int *val)
u8 buffer[3];
int ret;

- mutex_lock(&data->lock);
- ret = regmap_write(regmap, RM3100_REG_POLL, BIT(4 + idx));
- if (ret < 0)
- goto unlock_return;
+ scoped_guard(mutex, &data->lock) {
+ ret = regmap_write(regmap, RM3100_REG_POLL, BIT(4 + idx));
+ if (ret < 0)
+ return ret;

- ret = rm3100_wait_measurement(data);
- if (ret < 0)
- goto unlock_return;
+ ret = rm3100_wait_measurement(data);
+ if (ret < 0)
+ return ret;

- ret = regmap_bulk_read(regmap, RM3100_REG_MX2 + 3 * idx, buffer, 3);
- if (ret < 0)
- goto unlock_return;
- mutex_unlock(&data->lock);
+ ret = regmap_bulk_read(regmap, RM3100_REG_MX2 + 3 * idx, buffer, 3);
+ if (ret < 0)
+ return ret;
+ }

*val = sign_extend32(get_unaligned_be24(&buffer[0]), 23);

return IIO_VAL_INT;
-
-unlock_return:
- mutex_unlock(&data->lock);
- return ret;
}

#define RM3100_CHANNEL(axis, idx) \
--
2.53.0