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

From: Maxwell Doose

Date: Thu Apr 30 2026 - 08:47:40 EST


On Thu, Apr 30, 2026 at 7:41 AM Maxwell Doose <m32285159@xxxxxxxxx> 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.
>
> Suggested-by: Jonathan Cameron <jic23@xxxxxxxxxx>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Signed-off-by: Maxwell Doose <m32285159@xxxxxxxxx>
> ---
> v2:
> - The following excerpts are from the original cover letter:
> - Added small style fixes per Andy's suggestions (Adding blank lines,
> moving an if statement in a scoped_guard block).
> - Switched out scoped_guard() for guard(mutex)() in certain commits.
> - Fixed error in commit 4 where deadlocks could occur, as goto
> ignores __attribute__((cleanup)). This has been fixed by the above.
>
> v3:
> - Added new helper-wrapper function rm3100_guarded_regmap_bulk_read(),
> see commit message.
> - Squashed commit into one commit rather than four.
>
> v4:
> - Changed function signature of rm3100_guarded_regmap_bulk_read() to
> supply struct rm3100_data *data instead of struct mutex *lock per
> Andy.
> - Renamed rm3100_guarded_regmap_bulk_read() to
> rm3100_regmap_bulk_read_locked() per Andy.
>
> v5:
> - Fix kernel doc of rm3100_regmap_bulk_read_locked() per Andy.
> - Added Andy Shevchenko's reviewed-by tag.
>
> drivers/iio/magnetometer/rm3100-core.c | 93 ++++++++++++++------------
> 1 file changed, 50 insertions(+), 43 deletions(-)
>
[snip]

Hi, just wanted to put the link to where Andy gave me permission to
use his reviewed-by tag just to make sure no confusion arises.
https://lore.kernel.org/linux-iio/CAKqfh0H1tq1eC5h54G1Vft26Qkaa4nYEdhwQAk=1R6CNXgnveQ@xxxxxxxxxxxxxx/T/#m5ad582163d5d9620c59edcd1a78eceee070677f7

best regards,
maxwell