linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Alexandru Ardelean <alexandru.ardelean@analog.com>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<jonathan.cameron@huawei.com>, <dan.carpenter@oracle.com>
Subject: Re: [PATCH v2] iio: imu: adis16480: make sure provided frequency is positive
Date: Sat, 12 Oct 2019 14:15:51 +0100	[thread overview]
Message-ID: <20191012141551.761178d8@archlinux> (raw)
In-Reply-To: <20191008141537.31512-1-alexandru.ardelean@analog.com>

On Tue, 8 Oct 2019 17:15:37 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> 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>
applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan
> ---
> 
> Changelog v1 -> v2:
> * also check that val & val2 are not negative (in addition to checking if
>  't' is zero
> 
>  drivers/iio/imu/adis16480.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
> index 01dae50e985b..0bec1fea823d 100644
> --- a/drivers/iio/imu/adis16480.c
> +++ b/drivers/iio/imu/adis16480.c
> @@ -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;
>  
>  	/*


      reply	other threads:[~2019-10-12 13:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 14:15 [PATCH v2] iio: imu: adis16480: make sure provided frequency is positive Alexandru Ardelean
2019-10-12 13:15 ` 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=20191012141551.761178d8@archlinux \
    --to=jic23@kernel.org \
    --cc=alexandru.ardelean@analog.com \
    --cc=dan.carpenter@oracle.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@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 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).