All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Alexandru Ardelean <alexandru.ardelean@analog.com>
Cc: <linux-iio@vger.kernel.org>, Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] iio: imu: adis16460: fix variable signedness
Date: Sun, 18 Aug 2019 18:54:36 +0100	[thread overview]
Message-ID: <20190818185436.05969228@archlinux> (raw)
In-Reply-To: <20190816062835.25588-1-alexandru.ardelean@analog.com>

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)


      reply	other threads:[~2019-08-18 17:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16  6:28 [PATCH] iio: imu: adis16460: fix variable signedness Alexandru Ardelean
2019-08-18 17:54 ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190818185436.05969228@archlinux \
    --to=jic23@kernel.org \
    --cc=alexandru.ardelean@analog.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.