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

From: Maxwell Doose

Date: Sun May 10 2026 - 02:58:20 EST


On Sun, May 10, 2026 at 1:54 AM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxx> wrote:
>
> On Sat, May 09, 2026 at 07:52:00AM -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.
>
> ...
>
> > - mutex_lock(&state->lock);
> > - ret = sps30_do_meas(state, scan.data, ARRAY_SIZE(scan.data));
> > - mutex_unlock(&state->lock);
> > + scoped_guard(mutex, &state->lock)
> > + ret = sps30_do_meas(state, scan.data, ARRAY_SIZE(scan.data));
>
> > +
>
> It's the same mistake already had been told many times, do not add blank line
> to the coupled statements (usually assignment followed by a check).
>

Sorry! I tend to use that style for some of my other things. Will fix
for v2 (I have to send that anyways).

>
> > if (ret)
> > goto err;
>
> And looking at the code, it's rather better to have this lock inside
> sps30_do_meas() (it might require to create a locked wrapper as
> sps30_do_meas() while renaming the current one to __sps30_do_meas()
> to clarify locking rules).
>

Sounds good, can also add for v2.

best regards,
max



>
> --
> With Best Regards,
> Andy Shevchenko
>
>