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

From: Markus Elfring

Date: Mon Jun 01 2026 - 12:02:14 EST


> 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



> +++ 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?

Regards,
Markus