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

From: Andy Shevchenko

Date: Tue Jun 02 2026 - 05:20:06 EST


On Mon, Jun 01, 2026 at 11:52:34AM -0500, Maxwell Doose wrote:
> On Mon, 1 Jun 2026 17:38:44 +0200
> Markus Elfring <Markus.Elfring@xxxxxx> wrote:



> > > - mutex_lock(&state->lock);
> > > - ret = scd30_command_read(state, CMD_ASC, &val);
> > > - mutex_unlock(&state->lock);
> > > + guard(mutex)(&state->lock);
> > >
> > > - return ret ?: sysfs_emit(buf, "%d\n", val);
> > …
> >
> > How do you think about to preserve lock scopes by using scoped_guard() calls?
>
> Generally scoped_guard() (at least in my experience in iio) is frowned
> upon because of the hidden for loop that can make normal things (e.g.,
> break, continue) really weird, plus guard()() with {} is also (in my
> experience) more popular over scoped_guard(). In the past helpers have
> also been liked over both as well.

This is a slow path and printing under the lock can actually narrow the window
for value to change which means that it increases the chance the user gets
actual value and not the stale one.

--
With Best Regards,
Andy Shevchenko