Re: [PATCH 10/15] iio:adc:ad799x: Check event value range on write

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/04/2014 12:42 AM, Peter Meerwald wrote:
event values are 10 or 12 bit max., and need to be left-shifted
on ad7993, ad7997


This should probably be squashed in the previous patch. As that one updates how the write value is computed and this one how the read value is computed.

Signed-off-by: Peter Meerwald <pmeerw@xxxxxxxxxx>
---
  drivers/iio/adc/ad799x.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 0d8e950..dbc7c2b 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -368,9 +368,13 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
  	int ret;
  	struct ad799x_state *st = iio_priv(indio_dev);

+	if (val > GENMASK(chan->scan_type.realbits - 1, 0))
+		return -EINVAL;
+
  	mutex_lock(&indio_dev->mlock);
  	ret = i2c_smbus_write_word_swapped(st->client,
-		ad799x_threshold_reg(chan, dir, info), val);
+		ad799x_threshold_reg(chan, dir, info),
+		val << chan->scan_type.shift);
  	mutex_unlock(&indio_dev->mlock);

  	return ret;


--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux