OSDN Git Service

iio: imu: adis16460: fix variable signedness
authorAlexandru Ardelean <alexandru.ardelean@analog.com>
Fri, 16 Aug 2019 06:28:35 +0000 (09:28 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 18 Aug 2019 17:53:15 +0000 (18:53 +0100)
commit519808425e1941563ca25af5caefe7261f6cc8a4
tree59dfa7f7837bb75931c3f4a0919145301093a00d
parentc0af3b61b50810fd73926be0d5f59cd6d8f8ac52
iio: imu: adis16460: fix variable signedness

Caught via static-analysis checker:
```
drivers/iio/imu/adis16460.c
   152  static int adis16460_set_freq(struct iio_dev *indio_dev, int val, int val2)
   153  {
   154          struct adis16460 *st = iio_priv(indio_dev);
   155          unsigned int t;
                ^^^^^^^^^^^^^^

   156
   157          t =  val * 1000 + val2 / 1000;
   158          if (t <= 0)
                    ^^^^^^
Unsigned is not less than zero.
```

The types of `val` && `val2` are obtained from the IIO `write_raw` hook, so
userspace can provide negative values, which can cause weird behavior after
conversion to unsigned.

This patch changes the sign of variable `t` so that -EINVAL will be
returned for negative values as well.

Fixes: db6ed4d23dd1 ("iio: imu: Add support for the ADIS16460 IMU")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/adis16460.c