mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
iio: adc: ad7606: switch mutexes to guard
Switching to guard simplifies the code and avoids to take care to unlock the mutex in case of premature return. Signed-off-by: Guillaume Stols <gstols@baylibre.com> Reviewed-by: Nuno Sa <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
059fe4f8bb
commit
2956979dbd
1 changed files with 15 additions and 24 deletions
|
@ -69,19 +69,17 @@ static int ad7606_reg_access(struct iio_dev *indio_dev,
|
||||||
struct ad7606_state *st = iio_priv(indio_dev);
|
struct ad7606_state *st = iio_priv(indio_dev);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mutex_lock(&st->lock);
|
guard(mutex)(&st->lock);
|
||||||
|
|
||||||
if (readval) {
|
if (readval) {
|
||||||
ret = st->bops->reg_read(st, reg);
|
ret = st->bops->reg_read(st, reg);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err_unlock;
|
|
||||||
*readval = ret;
|
|
||||||
ret = 0;
|
|
||||||
} else {
|
|
||||||
ret = st->bops->reg_write(st, reg, writeval);
|
|
||||||
}
|
|
||||||
err_unlock:
|
|
||||||
mutex_unlock(&st->lock);
|
|
||||||
return ret;
|
return ret;
|
||||||
|
*readval = ret;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return st->bops->reg_write(st, reg, writeval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ad7606_read_samples(struct ad7606_state *st)
|
static int ad7606_read_samples(struct ad7606_state *st)
|
||||||
|
@ -124,19 +122,19 @@ static irqreturn_t ad7606_trigger_handler(int irq, void *p)
|
||||||
struct ad7606_state *st = iio_priv(indio_dev);
|
struct ad7606_state *st = iio_priv(indio_dev);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mutex_lock(&st->lock);
|
guard(mutex)(&st->lock);
|
||||||
|
|
||||||
ret = ad7606_read_samples(st);
|
ret = ad7606_read_samples(st);
|
||||||
if (ret == 0)
|
if (ret)
|
||||||
|
goto error_ret;
|
||||||
|
|
||||||
iio_push_to_buffers_with_timestamp(indio_dev, st->data,
|
iio_push_to_buffers_with_timestamp(indio_dev, st->data,
|
||||||
iio_get_time_ns(indio_dev));
|
iio_get_time_ns(indio_dev));
|
||||||
|
error_ret:
|
||||||
iio_trigger_notify_done(indio_dev->trig);
|
iio_trigger_notify_done(indio_dev->trig);
|
||||||
/* The rising edge of the CONVST signal starts a new conversion. */
|
/* The rising edge of the CONVST signal starts a new conversion. */
|
||||||
gpiod_set_value(st->gpio_convst, 1);
|
gpiod_set_value(st->gpio_convst, 1);
|
||||||
|
|
||||||
mutex_unlock(&st->lock);
|
|
||||||
|
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,19 +255,17 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
|
||||||
struct ad7606_state *st = iio_priv(indio_dev);
|
struct ad7606_state *st = iio_priv(indio_dev);
|
||||||
int i, ret, ch = 0;
|
int i, ret, ch = 0;
|
||||||
|
|
||||||
|
guard(mutex)(&st->lock);
|
||||||
|
|
||||||
switch (mask) {
|
switch (mask) {
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
mutex_lock(&st->lock);
|
|
||||||
i = find_closest(val2, st->scale_avail, st->num_scales);
|
i = find_closest(val2, st->scale_avail, st->num_scales);
|
||||||
if (st->sw_mode_en)
|
if (st->sw_mode_en)
|
||||||
ch = chan->address;
|
ch = chan->address;
|
||||||
ret = st->write_scale(indio_dev, ch, i);
|
ret = st->write_scale(indio_dev, ch, i);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
mutex_unlock(&st->lock);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
st->range[ch] = i;
|
st->range[ch] = i;
|
||||||
mutex_unlock(&st->lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
|
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
|
||||||
|
@ -277,14 +273,9 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
i = find_closest(val, st->oversampling_avail,
|
i = find_closest(val, st->oversampling_avail,
|
||||||
st->num_os_ratios);
|
st->num_os_ratios);
|
||||||
mutex_lock(&st->lock);
|
|
||||||
ret = st->write_os(indio_dev, i);
|
ret = st->write_os(indio_dev, i);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
mutex_unlock(&st->lock);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
st->oversampling = st->oversampling_avail[i];
|
|
||||||
mutex_unlock(&st->lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Reference in a new issue