summaryrefslogtreecommitdiff
path: root/drivers/staging/iio/gyro/adis16260_core.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-07-17 15:44:00 +0100
committerJonathan Cameron <jic23@kernel.org>2013-08-03 18:41:20 +0100
commitf4f87d04116ab2f1419f1e85c1c9504536858b88 (patch)
tree9e730d0d6d639f2f0aa1b58c06526c776c5fe0d4 /drivers/staging/iio/gyro/adis16260_core.c
parent988c79a95e30dac019777e818cbfab6fdc4057b4 (diff)
staging:iio:adis16260: Add value range check for calibscale/-bias
Instead of just cutting of the upper bits of the value make sure that the value is in the valid range and return an error if it is not. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging/iio/gyro/adis16260_core.c')
-rw-r--r--drivers/staging/iio/gyro/adis16260_core.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
index a01c2438302f..55e67959b054 100644
--- a/drivers/staging/iio/gyro/adis16260_core.c
+++ b/drivers/staging/iio/gyro/adis16260_core.c
@@ -311,18 +311,21 @@ static int adis16260_write_raw(struct iio_dev *indio_dev,
long mask)
{
struct adis *adis = iio_priv(indio_dev);
- int bits = 12;
- s16 val16;
u8 addr;
+
switch (mask) {
case IIO_CHAN_INFO_CALIBBIAS:
- val16 = val & ((1 << bits) - 1);
+ if (val < -2048 || val >= 2048)
+ return -EINVAL;
+
addr = adis16260_addresses[chan->scan_index][0];
- return adis_write_reg_16(adis, addr, val16);
+ return adis_write_reg_16(adis, addr, val);
case IIO_CHAN_INFO_CALIBSCALE:
- val16 = val & ((1 << bits) - 1);
+ if (val < 0 || val >= 4096)
+ return -EINVAL;
+
addr = adis16260_addresses[chan->scan_index][1];
- return adis_write_reg_16(adis, addr, val16);
+ return adis_write_reg_16(adis, addr, val);
}
return -EINVAL;
}