Re: [PATCH v5] iio: magnetometer: rm3100: Modernize locking and refactor control flow

From: Andy Shevchenko

Date: Thu Apr 30 2026 - 09:04:12 EST


On Thu, Apr 30, 2026 at 07:41:47AM -0500, Maxwell Doose wrote:
> Replace mutex_lock() and mutex_unlock() calls in rm3100-core.c with
> the more modern guard(mutex)() family. This will help modernize the
> driver and bring it up-to-date with modern available macros/functions.
>
> While replacing mutex_lock() and mutex_unlock(), the critical sections
> of rm3100_read_mag() and rm3100_get_samp_freq() have been extended to
> include negligible operations for cleaner logic.
>
> Add new helper-wrapper function rm3100_guarded_regmap_bulk_read() to
> help keep rm3100_trigger_handler() switch-cases clean while maintaining
> mutex locking and avoiding re-entrancy risks from potential callbacks.
>
> While at it, remove redundant gotos where applicable, and use direct
> returns instead. In addition, remove regmap variable in
> rm3100_trigger_handler() as its references have been replaced with
> variable data.

...

> + ret = rm3100_regmap_bulk_read_locked(data, RM3100_REG_MX2 + 3 * bit,
> + data->buffer, 3);

Jonathan, if you feel to tweak this to make it shorter, I mentioned previously
this:

ret = rm3100_regmap_bulk_read_locked(data,
RM3100_REG_MX2 + 3 * bit,
data->buffer, 3);

> + if (ret < 0)
> goto done;

I confirm that my Rb stays with or without this change.
Maxwell, no need to resend for this.

--
With Best Regards,
Andy Shevchenko