Re: [PATCH v2] staging: iio: impedance-analyzer: ad5933: use guard(mutex) in ad5933_show()
From: Jonathan Cameron
Date: Sun Oct 25 2026 - 22:41:36 EST
On Mon, 19 Oct 2026 22:09:12 +0300
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:
> 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");
>
Maybe call it something else here as its not the range index that I can see.