mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +02:00
iio: dac: ad5686: read_raw/write_raw: use guard(mutex)()
Use guarded mutex lock to facilitate code review when adding new attributes. This will allow for early returns, avoiding error-prone locking and unlocking in error paths. This also adds missing include linux/cleanup.h. Gain-control support will allow the scale attribute to be configurable. Reviewed-by: Maxwell Doose <m32285159@gmail.com> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Reviewed-by: David Lechner <dlechner@baylibre.com> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
This commit is contained in:
parent
154a7560b4
commit
32052904ae
|
|
@ -8,6 +8,7 @@
|
|||
#include <linux/array_size.h>
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/dev_printk.h>
|
||||
#include <linux/errno.h>
|
||||
|
|
@ -177,11 +178,11 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
|
|||
struct ad5686_state *st = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
guard(mutex)(&st->lock);
|
||||
|
||||
switch (m) {
|
||||
case IIO_CHAN_INFO_RAW:
|
||||
mutex_lock(&st->lock);
|
||||
ret = ad5686_read(st, chan->address);
|
||||
mutex_unlock(&st->lock);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = (ret >> chan->scan_type.shift) &
|
||||
|
|
@ -202,23 +203,19 @@ static int ad5686_write_raw(struct iio_dev *indio_dev,
|
|||
long mask)
|
||||
{
|
||||
struct ad5686_state *st = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
guard(mutex)(&st->lock);
|
||||
|
||||
switch (mask) {
|
||||
case IIO_CHAN_INFO_RAW:
|
||||
if (val >= (1 << chan->scan_type.realbits) || val < 0)
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&st->lock);
|
||||
ret = ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N,
|
||||
chan->address, val << chan->scan_type.shift);
|
||||
mutex_unlock(&st->lock);
|
||||
break;
|
||||
return ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N,
|
||||
chan->address, val << chan->scan_type.shift);
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct iio_info ad5686_info = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user