Re: [PATCH v6] iio: chemical: scd30: Replace manual locking with RAII locking
From: Maxwell Doose
Date: Mon Jun 01 2026 - 12:58:52 EST
Hi Markus,
On Mon, 1 Jun 2026 17:38:44 +0200
Markus Elfring <Markus.Elfring@xxxxxx> wrote:
> > scd30_core.c currently uses manual mutex_lock() and mutex_unlock()
> > calls. Replace them with the newer guard(mutex)() for cleaner RAII
> > patterns and to improve maintainability.
> …
> > In addition, small refactor to replace "?:" operator with regular
> > if/else returns.
>
> How does such an information fit to a known patch requirement?
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.1-rc5#n81
>
Good point. However, I think that it's such a small change that nobody
is going to care that much. We'll see what Jonathan has to say, I
suppose.
>
> …
> > +++ b/drivers/iio/chemical/scd30_core.c
> > @@ -368,11 +368,13 @@ static ssize_t calibration_auto_enable_show(struct device *dev, struct device_at
> > int ret;
> > u16 val;
> >
> > - 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.
--
best regards,
max