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

Jonathan Cameron
2026-04-28T15:25:08Z

On Tue, 28 Apr 2026 08:59:48 -0500
Maxwell Doose <m32285159@gmail.com> wrote:

> On Tue, Apr 28, 2026 at 8:26 AM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
>
> > > - 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);
> >
> > > +
> >
> > Redundant blank line as ret is defined elsewhere.
>
> Shoot. I'm away right now but once I get back I can fix that.

Given the function is:
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;
*val = rm3100_samp_rates[tmp - RM3100_TMRC_OFFSET][0];
*val2 = rm3100_samp_rates[tmp - RM3100_TMRC_OFFSET][1];

return IIO_VAL_INT_PLUS_MICRO;
}

I'd just use a guard and not worry about two value lookups from static const data
being under the guard()

Why is this series broken up into lots of patches doing same type of change
in different places? This could definitely be combined with the previous patch.

Thanks,

Jonathan

>
> best regards,
> maxwell