Re: [PATCH v4] iio: imu: kmx61: Use guard(mutex)() over manual locking

From: Maxwell Doose

Date: Wed May 06 2026 - 10:58:31 EST


On Wed, May 6, 2026 at 4:06 AM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxx> wrote:
>
> On Tue, May 05, 2026 at 05:07:19PM -0500, Maxwell Doose wrote:
[snip]
> > - case IIO_CHAN_INFO_SAMP_FREQ:
> > + case IIO_CHAN_INFO_SAMP_FREQ: {
> > if (chan->type != IIO_ACCEL && chan->type != IIO_MAGN)
> > return -EINVAL;
> >
> > - mutex_lock(&data->lock);
> > - ret = kmx61_get_odr(data, val, val2, chan->address);
> > - mutex_unlock(&data->lock);
> > + scoped_guard(mutex, &data->lock)
> > + ret = kmx61_get_odr(data, val, val2, chan->address);
> > if (ret)
> > return -EINVAL;
> > return IIO_VAL_INT_PLUS_MICRO;
> > }
> > + }
> > return -EINVAL;
>
> For making the above less ambiguous, add default case here instead of the
> standalone return.
>

Sounds good, I'll get that into the next version.

>
> }
> default:
> return -EINVAL;
> }
>
> > }
>
> ...
>
> > static int kmx61_runtime_suspend(struct device *dev)
> > {
> > struct kmx61_data *data = i2c_get_clientdata(to_i2c_client(dev));
> > - int ret;
> >
> > - mutex_lock(&data->lock);
> > - ret = kmx61_set_mode(data, KMX61_ALL_STBY, KMX61_ACC | KMX61_MAG, true);
> > - mutex_unlock(&data->lock);
> > -
> > - return ret;
> > + guard(mutex)(&data->lock);
>
> Leave a blank line here. Same applies to all guard()() cases like this.
>

Ah, got it. I'm used to grouping related stuff in the code so to me
it's a bit strange but I'll also add that in the next version.

best regards,
max



>
> > + return kmx61_set_mode(data, KMX61_ALL_STBY, KMX61_ACC | KMX61_MAG, true);
> > }
>
> --
> With Best Regards,
> Andy Shevchenko
>
>