Commit 129e8619 authored by Jonathan Cameron's avatar Jonathan Cameron

iio: adc: ad7091r-base: Use auto cleanup of locks.

Done to reduce boilerplate and simplify code flow by allowing early
returns with the lock automatically released.
Reviewed-by: default avatarNuno Sa <nuno.a@analog.com>
Link: https://lore.kernel.org/r/20240128150537.44592-11-jic23@kernel.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 1fa220ec
...@@ -86,28 +86,25 @@ static int ad7091r_read_raw(struct iio_dev *iio_dev, ...@@ -86,28 +86,25 @@ static int ad7091r_read_raw(struct iio_dev *iio_dev,
unsigned int read_val; unsigned int read_val;
int ret; int ret;
mutex_lock(&st->lock); guard(mutex)(&st->lock);
switch (m) { switch (m) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
if (st->mode != AD7091R_MODE_COMMAND) { if (st->mode != AD7091R_MODE_COMMAND)
ret = -EBUSY; return -EBUSY;
goto unlock;
}
ret = ad7091r_read_one(iio_dev, chan->channel, &read_val); ret = ad7091r_read_one(iio_dev, chan->channel, &read_val);
if (ret) if (ret)
goto unlock; return ret;
*val = read_val; *val = read_val;
ret = IIO_VAL_INT; return IIO_VAL_INT;
break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
if (st->vref) { if (st->vref) {
ret = regulator_get_voltage(st->vref); ret = regulator_get_voltage(st->vref);
if (ret < 0) if (ret < 0)
goto unlock; return ret;
*val = ret / 1000; *val = ret / 1000;
} else { } else {
...@@ -115,17 +112,11 @@ static int ad7091r_read_raw(struct iio_dev *iio_dev, ...@@ -115,17 +112,11 @@ static int ad7091r_read_raw(struct iio_dev *iio_dev,
} }
*val2 = chan->scan_type.realbits; *val2 = chan->scan_type.realbits;
ret = IIO_VAL_FRACTIONAL_LOG2; return IIO_VAL_FRACTIONAL_LOG2;
break;
default: default:
ret = -EINVAL; return -EINVAL;
break;
} }
unlock:
mutex_unlock(&st->lock);
return ret;
} }
static int ad7091r_read_event_config(struct iio_dev *indio_dev, static int ad7091r_read_event_config(struct iio_dev *indio_dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment