[PATCH v2 4/4] iio: magnetometer: rm3100: Use guard(mutex)() in rm3100_trigger_handler()

Maxwell Doose
2026-04-28T12:46:52Z

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

Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
v2:
- Switched out scoped_guard() for guard(mutex)().
- Because of the replacement of scoped_guard(), fixed an error due to
gotos bypassing __attribute__((cleanup)).

drivers/iio/magnetometer/rm3100-core.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
index eb59ea8d5bf5..fdee82c1290f 100644
--- a/drivers/iio/magnetometer/rm3100-core.c
+++ b/drivers/iio/magnetometer/rm3100-core.c
@@ -459,11 +459,11 @@ static irqreturn_t rm3100_trigger_handler(int irq, void *p)
struct regmap *regmap = data->regmap;
int ret, i, bit;

- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
+
switch (scan_mask) {
case BIT(0) | BIT(1) | BIT(2):
ret = regmap_bulk_read(regmap, RM3100_REG_MX2, data->buffer, 9);
- mutex_unlock(&data->lock);
if (ret < 0)
goto done;
/* Convert XXXYYYZZZxxx to XXXxYYYxZZZx. x for paddings. */
@@ -472,21 +472,18 @@ static irqreturn_t rm3100_trigger_handler(int irq, void *p)
break;
case BIT(0) | BIT(1):
ret = regmap_bulk_read(regmap, RM3100_REG_MX2, data->buffer, 6);
- mutex_unlock(&data->lock);
if (ret < 0)
goto done;
memmove(data->buffer + 4, data->buffer + 3, 3);
break;
case BIT(1) | BIT(2):
ret = regmap_bulk_read(regmap, RM3100_REG_MY2, data->buffer, 6);
- mutex_unlock(&data->lock);
if (ret < 0)
goto done;
memmove(data->buffer + 4, data->buffer + 3, 3);
break;
case BIT(0) | BIT(2):
ret = regmap_bulk_read(regmap, RM3100_REG_MX2, data->buffer, 9);
- mutex_unlock(&data->lock);
if (ret < 0)
goto done;
memmove(data->buffer + 4, data->buffer + 6, 3);
@@ -495,12 +492,9 @@ static irqreturn_t rm3100_trigger_handler(int irq, void *p)
for_each_set_bit(bit, &scan_mask, mask_len) {
ret = regmap_bulk_read(regmap, RM3100_REG_MX2 + 3 * bit,
data->buffer, 3);
- if (ret < 0) {
- mutex_unlock(&data->lock);
+ if (ret < 0)
goto done;
- }
}
- mutex_unlock(&data->lock);
}
/*
* Always using the same buffer so that we wouldn't need to set the
--
2.53.0