diff options
author | Alexandru Ardelean <alexandru.ardelean@analog.com> | 2019-10-08 10:15:37 -0400 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2019-10-12 09:14:45 -0400 |
commit | 24e1eb5c0d78cfb9750b690bbe997d4d59170258 (patch) | |
tree | 066ac4f07a773e1173bf2e2339e8c974d5fab0c5 | |
parent | 3f3d31622a2c18b644328965925110dd7638b376 (diff) |
iio: imu: adis16480: make sure provided frequency is positive
It could happen that either `val` or `val2` [provided from userspace] is
negative. In that case the computed frequency could get a weird value.
Fix this by checking that neither of the 2 variables is negative, and check
that the computed result is not-zero.
Fixes: e4f959390178 ("iio: imu: adis16480 switch sampling frequency attr to core support")
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r-- | drivers/iio/imu/adis16480.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c index b99d73887c9f..8743b2f376e2 100644 --- a/drivers/iio/imu/adis16480.c +++ b/drivers/iio/imu/adis16480.c | |||
@@ -317,8 +317,11 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2) | |||
317 | struct adis16480 *st = iio_priv(indio_dev); | 317 | struct adis16480 *st = iio_priv(indio_dev); |
318 | unsigned int t, reg; | 318 | unsigned int t, reg; |
319 | 319 | ||
320 | if (val < 0 || val2 < 0) | ||
321 | return -EINVAL; | ||
322 | |||
320 | t = val * 1000 + val2 / 1000; | 323 | t = val * 1000 + val2 / 1000; |
321 | if (t <= 0) | 324 | if (t == 0) |
322 | return -EINVAL; | 325 | return -EINVAL; |
323 | 326 | ||
324 | /* | 327 | /* |