staging:iio:adis16260: Add value range check for calibscale/-bias
authorLars-Peter Clausen <lars@metafoo.de>
Wed, 17 Jul 2013 14:44:00 +0000 (15:44 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sat, 3 Aug 2013 17:41:20 +0000 (18:41 +0100)
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>
drivers/staging/iio/gyro/adis16260_core.c

index a01c2438302f1283e77a3b53a3b1a544785b1ef3..55e67959b054346fc3c23b13afa3a67477f47b54 100644 (file)
@@ -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;
 }
This page took 0.0256189999999999 seconds and 5 git commands to generate.