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

From: Andy Shevchenko

Date: Tue Jun 02 2026 - 03:18:34 EST


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).

--
With Best Regards,
Andy Shevchenko