Skip to content

Commit d904b8e

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7124: use guard(mutex) to simplify return paths
Use guard(mutex) in a couple of functions to allow direct returns. This simplifies the code a bit and will make later changes easier. cleanup.h was already included for prior use of __free() Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 1b4956c commit d904b8e

1 file changed

Lines changed: 12 additions & 23 deletions

File tree

drivers/iio/adc/ad7124.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -739,24 +739,20 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
739739
{
740740
struct ad7124_state *st = iio_priv(indio_dev);
741741
unsigned int res, gain, full_scale, vref;
742-
int ret = 0;
743742

744-
mutex_lock(&st->cfgs_lock);
743+
guard(mutex)(&st->cfgs_lock);
745744

746745
switch (info) {
747746
case IIO_CHAN_INFO_SAMP_FREQ:
748-
if (val2 != 0 || val == 0) {
749-
ret = -EINVAL;
750-
break;
751-
}
747+
if (val2 != 0 || val == 0)
748+
return -EINVAL;
752749

753750
ad7124_set_channel_odr(st, chan->address, val);
754-
break;
751+
752+
return 0;
755753
case IIO_CHAN_INFO_SCALE:
756-
if (val != 0) {
757-
ret = -EINVAL;
758-
break;
759-
}
754+
if (val != 0)
755+
return -EINVAL;
760756

761757
if (st->channels[chan->address].cfg.bipolar)
762758
full_scale = 1 << (chan->scan_type.realbits - 1);
@@ -772,13 +768,10 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
772768
st->channels[chan->address].cfg.live = false;
773769

774770
st->channels[chan->address].cfg.pga_bits = res;
775-
break;
771+
return 0;
776772
default:
777-
ret = -EINVAL;
773+
return -EINVAL;
778774
}
779-
780-
mutex_unlock(&st->cfgs_lock);
781-
return ret;
782775
}
783776

784777
static int ad7124_reg_access(struct iio_dev *indio_dev,
@@ -810,23 +803,19 @@ static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
810803
int ret;
811804
int i;
812805

813-
mutex_lock(&st->cfgs_lock);
806+
guard(mutex)(&st->cfgs_lock);
807+
814808
for (i = 0; i < st->num_channels; i++) {
815809
bit_set = test_bit(i, scan_mask);
816810
if (bit_set)
817811
ret = __ad7124_set_channel(&st->sd, i);
818812
else
819813
ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_ENABLE,
820814
0, 2);
821-
if (ret < 0) {
822-
mutex_unlock(&st->cfgs_lock);
823-
815+
if (ret < 0)
824816
return ret;
825-
}
826817
}
827818

828-
mutex_unlock(&st->cfgs_lock);
829-
830819
return 0;
831820
}
832821

0 commit comments

Comments
 (0)