Commit 51980842 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

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: db6ed4d2 ("iio: imu: Add support for the ADIS16460 IMU")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent c0af3b61
...@@ -152,7 +152,7 @@ static int adis16460_debugfs_init(struct iio_dev *indio_dev) ...@@ -152,7 +152,7 @@ static int adis16460_debugfs_init(struct iio_dev *indio_dev)
static int adis16460_set_freq(struct iio_dev *indio_dev, int val, int val2) static int adis16460_set_freq(struct iio_dev *indio_dev, int val, int val2)
{ {
struct adis16460 *st = iio_priv(indio_dev); struct adis16460 *st = iio_priv(indio_dev);
unsigned int t; int t;
t = val * 1000 + val2 / 1000; t = val * 1000 + val2 / 1000;
if (t <= 0) if (t <= 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment