summaryrefslogtreecommitdiff
path: root/drivers/iio/adc/ad799x.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-06-29 09:43:23 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-06-29 09:43:23 -0700
commit6b64168de843b16e96a22f9e98c6afc92ee1da71 (patch)
tree6454d5021b9abfcb70ebcc52c726c0926f3775d0 /drivers/iio/adc/ad799x.c
parentff4f58f0ca5dee33a80a72393dd195de9284702b (diff)
parenta2c12493ed7e63a18cef33a71686d12ffcd6600e (diff)
Merge tag 'iio-fixes-for-3.16b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: Second set of IIO fixes for the 3.16 cycle. * A fix for a bug in setting threshold levels within the ad799x driver which prevents correct setting of the thresholds. * In ad7291 fix an case where a ERR_PTR value was returned directly instead of having PTR_ERR applied. Hence it would report success instead of failure. * of_iio_channel_get_by_name returned a non null pointer if it fails and the callee was expecting NULL to indicate failure. Fixed by returning NULL in the error cases.
Diffstat (limited to 'drivers/iio/adc/ad799x.c')
-rw-r--r--drivers/iio/adc/ad799x.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 39b4cb48d738..6eba301ee03d 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -427,9 +427,12 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
int ret;
struct ad799x_state *st = iio_priv(indio_dev);
+ if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
+ return -EINVAL;
+
mutex_lock(&indio_dev->mlock);
ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
- val);
+ val << chan->scan_type.shift);
mutex_unlock(&indio_dev->mlock);
return ret;
@@ -452,7 +455,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
mutex_unlock(&indio_dev->mlock);
if (ret < 0)
return ret;
- *val = valin;
+ *val = (valin >> chan->scan_type.shift) &
+ RES_MASK(chan->scan_type.realbits);
return IIO_VAL_INT;
}