Skip to content

Commit 24e1eb5

Browse files
commodojic23
authored andcommitted
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: e4f9593 ("iio: imu: adis16480 switch sampling frequency attr to core support") Signed-off-by: Alexandru Ardelean <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 3f3d316 commit 24e1eb5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/iio/imu/adis16480.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
317317
struct adis16480 *st = iio_priv(indio_dev);
318318
unsigned int t, reg;
319319

320+
if (val < 0 || val2 < 0)
321+
return -EINVAL;
322+
320323
t = val * 1000 + val2 / 1000;
321-
if (t <= 0)
324+
if (t == 0)
322325
return -EINVAL;
323326

324327
/*

0 commit comments

Comments
 (0)