diff options
Diffstat (limited to 'drivers/iio/adc/ad799x.c')
-rw-r--r-- | drivers/iio/adc/ad799x.c | 8 |
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, | |||
427 | int ret; | 427 | int ret; |
428 | struct ad799x_state *st = iio_priv(indio_dev); | 428 | struct ad799x_state *st = iio_priv(indio_dev); |
429 | 429 | ||
430 | if (val < 0 || val > RES_MASK(chan->scan_type.realbits)) | ||
431 | return -EINVAL; | ||
432 | |||
430 | mutex_lock(&indio_dev->mlock); | 433 | mutex_lock(&indio_dev->mlock); |
431 | ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info), | 434 | ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info), |
432 | val); | 435 | val << chan->scan_type.shift); |
433 | mutex_unlock(&indio_dev->mlock); | 436 | mutex_unlock(&indio_dev->mlock); |
434 | 437 | ||
435 | return ret; | 438 | return ret; |
@@ -452,7 +455,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev, | |||
452 | mutex_unlock(&indio_dev->mlock); | 455 | mutex_unlock(&indio_dev->mlock); |
453 | if (ret < 0) | 456 | if (ret < 0) |
454 | return ret; | 457 | return ret; |
455 | *val = valin; | 458 | *val = (valin >> chan->scan_type.shift) & |
459 | RES_MASK(chan->scan_type.realbits); | ||
456 | 460 | ||
457 | return IIO_VAL_INT; | 461 | return IIO_VAL_INT; |
458 | } | 462 | } |