Commit fde272e7 authored by Kister Genesis Jimenez's avatar Kister Genesis Jimenez Committed by Jonathan Cameron

iio: gyro: adxrs290: fix data signedness

Properly sign-extend the rate and temperature data.

Fixes: 2c8920ff ("iio: gyro: Add driver support for ADXRS290")
Signed-off-by: default avatarKister Genesis Jimenez <kister.jimenez@analog.com>
Signed-off-by: default avatarNuno Sá <nuno.sa@analog.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20211115104147.18669-1-nuno.sa@analog.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 66611464
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
#include <linux/bitfield.h> #include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -124,7 +125,7 @@ static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int * ...@@ -124,7 +125,7 @@ static int adxrs290_get_rate_data(struct iio_dev *indio_dev, const u8 cmd, int *
goto err_unlock; goto err_unlock;
} }
*val = temp; *val = sign_extend32(temp, 15);
err_unlock: err_unlock:
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
...@@ -146,7 +147,7 @@ static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val) ...@@ -146,7 +147,7 @@ static int adxrs290_get_temp_data(struct iio_dev *indio_dev, int *val)
} }
/* extract lower 12 bits temperature reading */ /* extract lower 12 bits temperature reading */
*val = temp & 0x0FFF; *val = sign_extend32(temp, 11);
err_unlock: err_unlock:
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment