Re: [PATCH] staging: iio: frequency: ad9832: use guard(mutex)

From: Joshua Crofts

Date: Sun Oct 18 2026 - 12:01:31 EST


On Sun, 18 Oct 2026 13:26:04 +0300
Melih Emik <melihemik@xxxxxxxxxxx> wrote:

> In ad9832_write(), manual mutex handling via mutex_lock() and
> mutex_unlock() necessitates error-exit trampolines (goto error_ret),
> intermediate variables, and deferred returns. This pattern is prone
> to unlock-omission bugs during refactoring and clutters the control
> flow.
>
> Modernize the locking by using guard(mutex) from <linux/cleanup.h>.
> Scope-based resource management automatically releases the lock upon
> exiting the lexical scope, which enables immediate error propagation
> at call sites, removes the error_ret label, and simplifies the control
> flow across all switch cases.
>
> Tested:
> - Compiled with W=1 on x86_64 with zero warnings.
> - Verified with lockdep and debug mutexes enabled
> (CONFIG_PROVE_LOCKING=y, CONFIG_DEBUG_MUTEXES=y).
> - Boot-tested full bzImage in QEMU with initcall_debug, confirming
> successful driver initialization (ad9832_driver_init returned 0)
> and zero lockdep warnings.
> - Disassembly inspected via objdump to ensure mutex_unlock on all
> exit paths.
> - Verified with scripts/checkpatch.pl (0 errors, 0 warnings).

The Tested: part goes under the ---, no need to preserve this info
in the git log.

--
Kind regards,
Joshua Crofts