linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: adis16460: fix variable signedness
@ 2019-08-16  6:28 Alexandru Ardelean
  2019-08-18 17:54 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2019-08-16  6:28 UTC (permalink / raw)
  To: linux-iio; +Cc: jic23, Alexandru Ardelean, Dan Carpenter

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>
---
 drivers/iio/imu/adis16460.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/adis16460.c b/drivers/iio/imu/adis16460.c
index 1ef11640ee20..6aed9e84abbf 100644
--- a/drivers/iio/imu/adis16460.c
+++ b/drivers/iio/imu/adis16460.c
@@ -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)
 {
 	struct adis16460 *st = iio_priv(indio_dev);
-	unsigned int t;
+	int t;
 
 	t =  val * 1000 + val2 / 1000;
 	if (t <= 0)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: imu: adis16460: fix variable signedness
  2019-08-16  6:28 [PATCH] iio: imu: adis16460: fix variable signedness Alexandru Ardelean
@ 2019-08-18 17:54 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-08-18 17:54 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Dan Carpenter

On Fri, 16 Aug 2019 09:28:35 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> 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>

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/adis16460.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/imu/adis16460.c b/drivers/iio/imu/adis16460.c
> index 1ef11640ee20..6aed9e84abbf 100644
> --- a/drivers/iio/imu/adis16460.c
> +++ b/drivers/iio/imu/adis16460.c
> @@ -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)
>  {
>  	struct adis16460 *st = iio_priv(indio_dev);
> -	unsigned int t;
> +	int t;
>  
>  	t =  val * 1000 + val2 / 1000;
>  	if (t <= 0)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-18 17:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-16  6:28 [PATCH] iio: imu: adis16460: fix variable signedness Alexandru Ardelean
2019-08-18 17:54 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).