Skip to content

Commit f3c1ef2

Browse files
guilhermeivojic23
authored andcommitted
iio: adc: xilinx-ams: use guard(mutex) for automatic locking
Replace open-coded mutex_lock()/mutex_unlock() pairs with guard(mutex) to simplify locking and ensure proper unlock on all control flow paths. This removes explicit unlock handling, reduces boilerplate, and avoids potential mistakes in error paths while keeping the behavior unchanged. Signed-off-by: Guilherme Ivo Bozi <guilherme.bozi@usp.br> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Reviewed-by: Salih Erim <salih.erim@amd.com> Tested-by: Salih Erim <salih.erim@amd.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 947eb6f commit f3c1ef2

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

drivers/iio/adc/xilinx-ams.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -720,22 +720,20 @@ static int ams_read_raw(struct iio_dev *indio_dev,
720720
int ret;
721721

722722
switch (mask) {
723-
case IIO_CHAN_INFO_RAW:
724-
mutex_lock(&ams->lock);
723+
case IIO_CHAN_INFO_RAW: {
724+
guard(mutex)(&ams->lock);
725725
if (chan->scan_index >= AMS_CTRL_SEQ_BASE) {
726726
ret = ams_read_vcc_reg(ams, chan->address, val);
727727
if (ret)
728-
goto unlock_mutex;
728+
return ret;
729729
ams_enable_channel_sequence(indio_dev);
730730
} else if (chan->scan_index >= AMS_PS_SEQ_MAX)
731731
*val = readl(ams->pl_base + chan->address);
732732
else
733733
*val = readl(ams->ps_base + chan->address);
734734

735-
ret = IIO_VAL_INT;
736-
unlock_mutex:
737-
mutex_unlock(&ams->lock);
738-
return ret;
735+
return IIO_VAL_INT;
736+
}
739737
case IIO_CHAN_INFO_SCALE:
740738
switch (chan->type) {
741739
case IIO_VOLTAGE:
@@ -939,7 +937,7 @@ static int ams_write_event_config(struct iio_dev *indio_dev,
939937

940938
alarm = ams_get_alarm_mask(chan->scan_index);
941939

942-
mutex_lock(&ams->lock);
940+
guard(mutex)(&ams->lock);
943941

944942
if (state)
945943
ams->alarm_mask |= alarm;
@@ -948,8 +946,6 @@ static int ams_write_event_config(struct iio_dev *indio_dev,
948946

949947
ams_update_alarm(ams, ams->alarm_mask);
950948

951-
mutex_unlock(&ams->lock);
952-
953949
return 0;
954950
}
955951

@@ -962,15 +958,13 @@ static int ams_read_event_value(struct iio_dev *indio_dev,
962958
struct ams *ams = iio_priv(indio_dev);
963959
unsigned int offset = ams_get_alarm_offset(chan->scan_index, dir);
964960

965-
mutex_lock(&ams->lock);
961+
guard(mutex)(&ams->lock);
966962

967963
if (chan->scan_index >= AMS_PS_SEQ_MAX)
968964
*val = readl(ams->pl_base + offset);
969965
else
970966
*val = readl(ams->ps_base + offset);
971967

972-
mutex_unlock(&ams->lock);
973-
974968
return IIO_VAL_INT;
975969
}
976970

@@ -983,7 +977,7 @@ static int ams_write_event_value(struct iio_dev *indio_dev,
983977
struct ams *ams = iio_priv(indio_dev);
984978
unsigned int offset;
985979

986-
mutex_lock(&ams->lock);
980+
guard(mutex)(&ams->lock);
987981

988982
/* Set temperature channel threshold to direct threshold */
989983
if (chan->type == IIO_TEMP) {
@@ -1005,8 +999,6 @@ static int ams_write_event_value(struct iio_dev *indio_dev,
1005999
else
10061000
writel(val, ams->ps_base + offset);
10071001

1008-
mutex_unlock(&ams->lock);
1009-
10101002
return 0;
10111003
}
10121004

0 commit comments

Comments
 (0)