On Sun, 2025-02-09 at 18:06 +0000, Jonathan Cameron wrote: > From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> > > This complex cleanup.h use case of conditional guards has proved > to be more trouble that it is worth in terms of false positive compiler > warnings and hard to read code. > > Move directly to the new claim/release_direct() that allow sparse > to check for unbalanced context. Also use guard() to simplify mutex > unlock paths. > > Cc: Nuno Sa <nuno.sa@xxxxxxxxxx> > Reviewed-by: David Lechner <dlechner@xxxxxxxxxxxx> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> > --- Reviewed-by: Nuno Sa <nuno.sa@xxxxxxxxxx> > drivers/iio/adc/ad9467.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c > index f30119b42ba0..f7a9f46ea0dc 100644 > --- a/drivers/iio/adc/ad9467.c > +++ b/drivers/iio/adc/ad9467.c > @@ -813,6 +813,18 @@ static int ad9467_read_raw(struct iio_dev *indio_dev, > } > } > > +static int __ad9467_update_clock(struct ad9467_state *st, long r_clk) > +{ > + int ret; > + > + ret = clk_set_rate(st->clk, r_clk); > + if (ret) > + return ret; > + > + guard(mutex)(&st->lock); > + return ad9467_calibrate(st); > +} > + > static int ad9467_write_raw(struct iio_dev *indio_dev, > struct iio_chan_spec const *chan, > int val, int val2, long mask) > @@ -842,14 +854,11 @@ static int ad9467_write_raw(struct iio_dev *indio_dev, > if (sample_rate == r_clk) > return 0; > > - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { > - ret = clk_set_rate(st->clk, r_clk); > - if (ret) > - return ret; > + if (!iio_device_claim_direct(indio_dev)) > + return -EBUSY; > > - guard(mutex)(&st->lock); > - ret = ad9467_calibrate(st); > - } > + ret = __ad9467_update_clock(st, r_clk); > + iio_device_release_direct(indio_dev); > return ret; > default: > return -EINVAL;