[PATCH v2 2/4] iio: magnetometer: rm3100: Use scoped_guard() in rm3100_get_samp_freq()

From: Maxwell Doose

Date: Tue Apr 28 2026 - 08:59:40 EST


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

Signed-off-by: Maxwell Doose <m32285159@xxxxxxxxx>
---
v2:
- Move if statement into scoped_guard body per Andy.

drivers/iio/magnetometer/rm3100-core.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
index 426963935d60..9f25efb2d02d 100644
--- a/drivers/iio/magnetometer/rm3100-core.c
+++ b/drivers/iio/magnetometer/rm3100-core.c
@@ -280,11 +280,12 @@ static int rm3100_get_samp_freq(struct rm3100_data *data, int *val, int *val2)
unsigned int tmp;
int ret;

- mutex_lock(&data->lock);
- ret = regmap_read(data->regmap, RM3100_REG_TMRC, &tmp);
- mutex_unlock(&data->lock);
- if (ret < 0)
- return ret;
+ scoped_guard(mutex, &data->lock) {
+ ret = regmap_read(data->regmap, RM3100_REG_TMRC, &tmp);
+
+ if (ret < 0)
+ return ret;
+ }
*val = rm3100_samp_rates[tmp - RM3100_TMRC_OFFSET][0];
*val2 = rm3100_samp_rates[tmp - RM3100_TMRC_OFFSET][1];

--
2.53.0