Re: [PATCH] staging: iio: frequency: ad9832: use guard(mutex)
From: Andy Shevchenko
Date: Mon Oct 19 2026 - 05:30:11 EST
On Sun, Oct 18, 2026 at 05:55:58PM +0200, Joshua Crofts wrote:
> 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.
If it was tested on a real HW, the summary (like a couple of words only)
is still good to have in the commit message to leave a trail of the actual
HW that makes the change appear.
--
With Best Regards,
Andy Shevchenko