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

From: Andy Shevchenko

Date: Tue Jun 02 2026 - 03:17:06 EST


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?

--
With Best Regards,
Andy Shevchenko