iio: adxrs290: fix data signedness
Subsystems (3)
Nuno Sá
maintainerPATCH 1/1 iio: adxrs290: fix data signedness
From: Kister Genesis Jimenez <[email protected]>
Properly sign-extend the rate and temperature data.
--- drivers/iio/gyro/adxrs290.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/gyro/adxrs290.c +3 -2
@@ -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 &0x0FFF ,11 ); err_unlock:mutex_unlock (&st->lock);
Signature · 1 line
2.33.1
Quoted 4 lines · Nuno Sá
From: Kister Genesis Jimenez <[email protected]>
Properly sign-extend the rate and temperature data.
...
drivers/iio/gyro/adxrs290.c static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val) · line 150
Quoted 3 lines
/* extract lower 12 bits temperature reading */drivers/iio/gyro/adxrs290.c +1
-1- *val = temp &0x0FFF ; + *val =sign_extend32 (temp &0x0FFF ,11 );
What role does the ' & 0x0FFF' part play now?
Isn't it simply a dup (redundant) piece?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerQuoted 22 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Thursday, November 11, 2021 1:49 PM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>; Nishant Malpani <[email protected]>; Jimenez, Kister <[email protected]>
Subject: Re: [PATCH] iio: adxrs290: fix data signedness[External]
Quoted 4 lines · Nuno Sá
From: Kister Genesis Jimenez <[email protected]>
Properly sign-extend the rate and temperature data.
Quoted 8 lines
...
drivers/iio/gyro/adxrs290.c static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val) · line 150
Quoted 3 lines
/* extract lower 12 bits temperature reading */drivers/iio/gyro/adxrs290.c +1
-1- *val = temp &0x0FFF ; + *val =sign_extend32 (temp &0x0FFF ,11 );What role does the ' &
0x0FFF' part play now? Isn't it simply a dup (redundant) piece?
Oops, you're right. It serves no purpose as we shift out the bits that we do not care. My fault, I just acted as a bot...
- Nuno Sá