Re: [PATCH] iio: chemical: sps30: Replace manual locking with RAII locking
From: Andy Shevchenko
Date: Sun May 10 2026 - 02:54:13 EST
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).
> 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).
--
With Best Regards,
Andy Shevchenko