Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

David Lechner and committed by
Jonathan Cameron
d904b8e6 1b4956ca

+12 -23
+12 -23
drivers/iio/adc/ad7124.c
··· 739 739 { 740 740 struct ad7124_state *st = iio_priv(indio_dev); 741 741 unsigned int res, gain, full_scale, vref; 742 - int ret = 0; 743 742 744 - mutex_lock(&st->cfgs_lock); 743 + guard(mutex)(&st->cfgs_lock); 745 744 746 745 switch (info) { 747 746 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; 752 749 753 750 ad7124_set_channel_odr(st, chan->address, val); 754 - break; 751 + 752 + return 0; 755 753 case IIO_CHAN_INFO_SCALE: 756 - if (val != 0) { 757 - ret = -EINVAL; 758 - break; 759 - } 754 + if (val != 0) 755 + return -EINVAL; 760 756 761 757 if (st->channels[chan->address].cfg.bipolar) 762 758 full_scale = 1 << (chan->scan_type.realbits - 1); ··· 768 772 st->channels[chan->address].cfg.live = false; 769 773 770 774 st->channels[chan->address].cfg.pga_bits = res; 771 - break; 775 + return 0; 772 776 default: 773 - ret = -EINVAL; 777 + return -EINVAL; 774 778 } 775 - 776 - mutex_unlock(&st->cfgs_lock); 777 - return ret; 778 779 } 779 780 780 781 static int ad7124_reg_access(struct iio_dev *indio_dev, ··· 803 810 int ret; 804 811 int i; 805 812 806 - mutex_lock(&st->cfgs_lock); 813 + guard(mutex)(&st->cfgs_lock); 814 + 807 815 for (i = 0; i < st->num_channels; i++) { 808 816 bit_set = test_bit(i, scan_mask); 809 817 if (bit_set) ··· 812 818 else 813 819 ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_ENABLE, 814 820 0, 2); 815 - if (ret < 0) { 816 - mutex_unlock(&st->cfgs_lock); 817 - 821 + if (ret < 0) 818 822 return ret; 819 - } 820 823 } 821 - 822 - mutex_unlock(&st->cfgs_lock); 823 824 824 825 return 0; 825 826 }