Re: [PATCH v4] iio: chemical: sps30: Replace manual locking with RAII locking
From: Jonathan Cameron
Date: Tue Jun 02 2026 - 07:53:13 EST
On Tue, 2 Jun 2026 10:13:02 +0300
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:
> On Tue, May 19, 2026 at 04:26:02PM -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.
> >
> > Add guard(mutex)() into sps30_do_meas() as every caller locks it's call.
>
> ...
>
> > - 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);
>
> Hmm... msleep() under the mutex?
>
Device needs to ensure no other access to the hardware whilst a reading
is ongoing. Mutex being held over that sleep seems appropriate to me
given expectation is that any userspace code that is messing with other
paths that take the lock is shooting itself in the foot and should probably
be doing it's own serialization at a higher level (i.e. not hitting the
sysfs interface from mutliple threads).
Jonathan