]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
iio: imu: adis16480: make sure provided frequency is positive
authorAlexandru Ardelean <alexandru.ardelean@analog.com>
Tue, 8 Oct 2019 14:15:37 +0000 (17:15 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 12 Oct 2019 13:14:45 +0000 (14:14 +0100)
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>
drivers/iio/imu/adis16480.c

index b99d73887c9f3cd6c74e39cc6acd710663f58821..8743b2f376e277aa34ccefdb5979968d1db32f3a 100644 (file)
@@ -317,8 +317,11 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
        struct adis16480 *st = iio_priv(indio_dev);
        unsigned int t, reg;
 
+       if (val < 0 || val2 < 0)
+               return -EINVAL;
+
        t =  val * 1000 + val2 / 1000;
-       if (t <= 0)
+       if (t == 0)
                return -EINVAL;
 
        /*