Re: [PATCH v5] iio: chemical: sps30: Replace manual locking with RAII locking

From: Jonathan Cameron

Date: Tue Jun 02 2026 - 07:56:47 EST


On Tue, 2 Jun 2026 10:14:34 +0300
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

> On Sat, May 23, 2026 at 01:15:36PM -0500, Maxwell Doose wrote:
> > Replace manual mutex_lock() and mutex_unlock() calls with the much newer
> > guard(mutex)() and scoped_guard() macros to enable RAII patterns,
> > modernize the driver, and to increase readability.
> >
> > Move mutex locking into sps30_do_meas() and tune it up to use guard()(),
> > as every caller takes the lock anyways.
>
> ...
>
> > - mutex_lock(&state->lock);
> > + guard(mutex)(&state->lock);
> > +
> > ret = state->ops->write_cleaning_period(state, cpu_to_be32(val));
> > - if (ret) {
> > - mutex_unlock(&state->lock);
> > + if (ret)
> > return ret;
> > - }
> >
> > msleep(20);
>
> Same question as per v4 (yes, I see that it was in the original code).
>
I relied to v4. I think it is the correct thing to do as adds a penalty
for stupid userspace code and doesn't complicate the driver like other
solutions would do.

J