iio: accel: bma400: prevent setting accel scale too low
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 16 Jan 2020 10:08:29 +0000 (13:08 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 18 Jan 2020 13:33:11 +0000 (13:33 +0000)
This puts an upper bound on "val2" but it also needs to have a lower
bound (BMA400_SCALE_MIN).

Fixes: 465c811f1f20 ("iio: accel: Add driver for the BMA400")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/bma400_core.c

index ab4a158b35af93b67fcad1aa2e56931ff7f594e0..cc77f89c048bca1b6ef1d7c88d14b4e352b93ed2 100644 (file)
@@ -752,7 +752,8 @@ static int bma400_write_raw(struct iio_dev *indio_dev,
                mutex_unlock(&data->mutex);
                return ret;
        case IIO_CHAN_INFO_SCALE:
-               if (val != 0 || val2 > BMA400_SCALE_MAX)
+               if (val != 0 ||
+                   val2 < BMA400_SCALE_MIN || val2 > BMA400_SCALE_MAX)
                        return -EINVAL;
 
                mutex_lock(&data->mutex);