Re: [PATCH v2] staging: iio: impedance-analyzer: ad5933: use guard(mutex) in ad5933_show()
From: Andy Shevchenko
Date: Mon Oct 19 2026 - 15:09:27 EST
On Mon, Oct 19, 2026 at 03:02:48PM +0000, Nithishvelan M wrote:
> Use guard(mutex) to automatically manage the state lock in
> ad5933_show(). This simplifies the function by allowing direct returns
> from each switch case, eliminating the mutable return variables and
> manual mutex_unlock() calls.
...
> case AD5933_IN_PGA_GAIN:
> - len = sysfs_emit(buf, "%s\n",
> - (st->ctrl_hb & AD5933_CTRL_PGA_GAIN_1) ?
> - "1" : "0.2");
> - break;
> + return sysfs_emit(buf, "%s\n",
> + st->ctrl_hb & AD5933_CTRL_PGA_GAIN_1 ? "1" : "0.2");
You can (re-)use ridx here as well
ridx = st->ctrl_hb & AD5933_CTRL_PGA_GAIN_1;
return sysfs_emit(buf, "%s\n", ridx ? "1" : "0.2");
--
With Best Regards,
Andy Shevchenko