iio:accel:mma8452: check values to be written

Check values to be written to the device for valid lower and upper bounds.

Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Hartmut Knaack 2015-08-02 22:43:49 +02:00 committed by Jonathan Cameron
parent b9fddcdb44
commit 1121822618
1 changed files with 5 additions and 3 deletions

View File

@ -471,15 +471,17 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
switch (info) { switch (info) {
case IIO_EV_INFO_VALUE: case IIO_EV_INFO_VALUE:
return mma8452_change_config(data, MMA8452_TRANSIENT_THS, if (val < 0 || val > MMA8452_TRANSIENT_THS_MASK)
val & MMA8452_TRANSIENT_THS_MASK); return -EINVAL;
return mma8452_change_config(data, MMA8452_TRANSIENT_THS, val);
case IIO_EV_INFO_PERIOD: case IIO_EV_INFO_PERIOD:
steps = (val * USEC_PER_SEC + val2) / steps = (val * USEC_PER_SEC + val2) /
mma8452_transient_time_step_us[ mma8452_transient_time_step_us[
mma8452_get_odr_index(data)]; mma8452_get_odr_index(data)];
if (steps > 0xff) if (steps < 0 || steps > 0xff)
return -EINVAL; return -EINVAL;
return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT, return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT,