diff mbox series

[v3] iio: adxrs290: fix data signedness

Message ID 20211115104147.18669-1-nuno.sa@analog.com (mailing list archive)
State Accepted
Headers show
Series [v3] iio: adxrs290: fix data signedness | expand

Commit Message

Nuno Sa Nov. 15, 2021, 10:41 a.m. UTC
From: Kister Genesis Jimenez <kister.jimenez@analog.com>

Properly sign-extend the rate and temperature data.

Fixes: 2c8920fff1457 ("iio: gyro: Add driver support for ADXRS290")
Signed-off-by: Kister Genesis Jimenez <kister.jimenez@analog.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
changes in v2:
 * removed redundant temp & 0xFFF.

changes in v3:
 * full name in Signed-off-by tag.

 drivers/iio/gyro/adxrs290.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Andy Shevchenko Nov. 15, 2021, 10:57 a.m. UTC | #1
On Mon, Nov 15, 2021 at 12:41 PM Nuno Sá <nuno.sa@analog.com> wrote:
>
> From: Kister Genesis Jimenez <kister.jimenez@analog.com>
>
> Properly sign-extend the rate and temperature data.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Fixes: 2c8920fff1457 ("iio: gyro: Add driver support for ADXRS290")
> Signed-off-by: Kister Genesis Jimenez <kister.jimenez@analog.com>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> ---
> changes in v2:
>  * removed redundant temp & 0xFFF.
>
> changes in v3:
>  * full name in Signed-off-by tag.
>
>  drivers/iio/gyro/adxrs290.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
> index 3e0734ddafe3..600e9725da78 100644
> --- a/drivers/iio/gyro/adxrs290.c
> +++ b/drivers/iio/gyro/adxrs290.c
> @@ -7,6 +7,7 @@
>   */
>
>  #include <linux/bitfield.h>
> +#include <linux/bitops.h>
>  #include <linux/delay.h>
>  #include <linux/device.h>
>  #include <linux/kernel.h>
> @@ -124,7 +125,7 @@ static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *
>                 goto err_unlock;
>         }
>
> -       *val = temp;
> +       *val = sign_extend32(temp, 15);
>
>  err_unlock:
>         mutex_unlock(&st->lock);
> @@ -146,7 +147,7 @@ static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val)
>         }
>
>         /* extract lower 12 bits temperature reading */
> -       *val = temp & 0x0FFF;
> +       *val = sign_extend32(temp, 11);
>
>  err_unlock:
>         mutex_unlock(&st->lock);
> --
> 2.33.1
>
Jonathan Cameron Nov. 20, 2021, 5:55 p.m. UTC | #2
On Mon, 15 Nov 2021 12:57:46 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Mon, Nov 15, 2021 at 12:41 PM Nuno Sá <nuno.sa@analog.com> wrote:
> >
> > From: Kister Genesis Jimenez <kister.jimenez@analog.com>
> >
> > Properly sign-extend the rate and temperature data.  
> 
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

> 
> > Fixes: 2c8920fff1457 ("iio: gyro: Add driver support for ADXRS290")
> > Signed-off-by: Kister Genesis Jimenez <kister.jimenez@analog.com>
> > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> > ---
> > changes in v2:
> >  * removed redundant temp & 0xFFF.
> >
> > changes in v3:
> >  * full name in Signed-off-by tag.
> >
> >  drivers/iio/gyro/adxrs290.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
> > index 3e0734ddafe3..600e9725da78 100644
> > --- a/drivers/iio/gyro/adxrs290.c
> > +++ b/drivers/iio/gyro/adxrs290.c
> > @@ -7,6 +7,7 @@
> >   */
> >
> >  #include <linux/bitfield.h>
> > +#include <linux/bitops.h>
> >  #include <linux/delay.h>
> >  #include <linux/device.h>
> >  #include <linux/kernel.h>
> > @@ -124,7 +125,7 @@ static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *
> >                 goto err_unlock;
> >         }
> >
> > -       *val = temp;
> > +       *val = sign_extend32(temp, 15);
> >
> >  err_unlock:
> >         mutex_unlock(&st->lock);
> > @@ -146,7 +147,7 @@ static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val)
> >         }
> >
> >         /* extract lower 12 bits temperature reading */
> > -       *val = temp & 0x0FFF;
> > +       *val = sign_extend32(temp, 11);
> >
> >  err_unlock:
> >         mutex_unlock(&st->lock);
> > --
> > 2.33.1
> >  
> 
>
diff mbox series

Patch

diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
index 3e0734ddafe3..600e9725da78 100644
--- a/drivers/iio/gyro/adxrs290.c
+++ b/drivers/iio/gyro/adxrs290.c
@@ -7,6 +7,7 @@ 
  */
 
 #include <linux/bitfield.h>
+#include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
@@ -124,7 +125,7 @@  static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *
 		goto err_unlock;
 	}
 
-	*val = temp;
+	*val = sign_extend32(temp, 15);
 
 err_unlock:
 	mutex_unlock(&st->lock);
@@ -146,7 +147,7 @@  static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val)
 	}
 
 	/* extract lower 12 bits temperature reading */
-	*val = temp & 0x0FFF;
+	*val = sign_extend32(temp, 11);
 
 err_unlock:
 	mutex_unlock(&st->lock);