Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] iio: imu: adis16480: make sure provided frequency is positive
@ 2019-10-08 14:15 Alexandru Ardelean
  2019-10-12 13:15 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2019-10-08 14:15 UTC (permalink / raw)
  To: linux-iio, linux-kernel
  Cc: jic23, jonathan.cameron, dan.carpenter, Alexandru Ardelean

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

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;
 
 	/*
-- 
2.20.1


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

* Re: [PATCH v2] iio: imu: adis16480: make sure provided frequency is positive
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-10-12 13:15 UTC (permalink / raw)
  To: Alexandru Ardelean
  Cc: linux-iio, linux-kernel, jonathan.cameron, dan.carpenter

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;
>  
>  	/*


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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox