iio: accel: bma400: prevent setting accel scale too low

This puts an upper bound on "val2" but it also needs to have a lower
bound (BMA400_SCALE_MIN).

Fixes: 465c811f1f ("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>
This commit is contained in:
Dan Carpenter 2020-01-16 13:08:29 +03:00 committed by Jonathan Cameron
parent 84961af78c
commit 98496ccdf0

View 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);