Re: [PATCH 2/3] iio: filter: admv8818: Simplify locking with guard()

From: David Lechner

Date: Fri Feb 27 2026 - 11:15:53 EST


On 2/27/26 12:14 AM, Ethan Tidmore wrote:
> Use guard() instead of manual locking to simplify code.
>
> Signed-off-by: Ethan Tidmore <ethantidmore06@xxxxxxxxx>
> ---


> @@ -352,13 +344,8 @@ static int __admv8818_read_hpf_freq(struct admv8818_state *st, u64 *hpf_freq)
>
> static int admv8818_read_hpf_freq(struct admv8818_state *st, u64 *hpf_freq)
> {
> - int ret;
> -
> - mutex_lock(&st->lock);
> - ret = __admv8818_read_hpf_freq(st, hpf_freq);
> - mutex_unlock(&st->lock);
> -
> - return ret;
> + guard(mutex)(&st->lock);
> + return __admv8818_read_hpf_freq(st, hpf_freq);
> }

admv8818_read_hpf_freq() is the only caller of __admv8818_read_hpf_freq()
so we can drop the wrapper, move the guard to __admv8818_read_hpf_freq()
and rename it to admv8818_read_hpf_freq().

I didn't check all functions, but might be others places where we can do
this as well.