Re: [PATCH] staging: iio: frequency: ad9832: use guard(mutex)
From: Andy Shevchenko
Date: Tue Nov 10 2026 - 12:39:18 EST
On Tue, Nov 10, 2026 at 04:47:11PM +0000, Nithishvelan M wrote:
> Use guard(mutex) to automatically manage the state lock in
> ad9832_write(). This simplifies error handling by allowing direct
> returns from each switch case and error branch, eliminating the
> manual mutex_unlock() calls and the goto error label.
Patch is okay, below some ideas for further improvements.
...
> case AD9832_PINCTRL_EN:
> st->ctrl_ss &= ~AD9832_SELSRC;
> st->ctrl_ss |= FIELD_PREP(AD9832_SELSRC, val ? 0 : 1);
This is basically FIELD_MODIFY() (and in many similar places in the driver).
...
> case AD9832_FREQ_SYM:
> if (val == 1 || val == 0) {
> st->ctrl_fp &= ~AD9832_FREQ;
> st->ctrl_fp |= FIELD_PREP(AD9832_FREQ, val ? 1 : 0);
Here ternary is unneeded, however might be still okay to have to be consistent
with the above case(s).
...
> case AD9832_PHASE_SYM:
> - if (val > 3) {
> - ret = -EINVAL;
> - break;
> - }
> + if (val > 3)
> + return -EINVAL;
In the above and here we might use FIELD_FIT(), but I haven't checked
the actual ranges.
--
With Best Regards,
Andy Shevchenko