iio: imu: adis16400: Fix sign extension
Subsystems (2)
PATCH 1/1 iio: imu: adis16400: Fix sign extension
The intention is obviously to sign-extend a 12 bit quantity. But because of C's promotion rules, the assignment is equivalent to "val16 &= 0xfff;". Use the proper API for this.
Signed-off-by Rasmus Villemoes <[email protected]>
--- drivers/iio/imu/adis16400_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/imu/adis16400_core.c +2 -1
@@ -26,6 +26,7 @@#include <linux/list.h> #include <linux/module.h> #include <linux/debugfs.h> +#include <linux/bitops.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -414,7 +415,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,mutex_unlock (&indio_dev->mlock);if (ret)return ret; - val16 = ((val16 &0xFFF ) <<4 ) >>4 ; + val16 =sign_extend32 (val16,11 ); *val = val16;return IIO_VAL_INT ;case IIO_CHAN_INFO_OFFSET :
Signature · 1 line
2.1.3
Quoted 5 lines · Rasmus Villemoes
The intention is obviously to sign-extend a 12 bit quantity. But because of C's promotion rules, the assignment is equivalent to "val16 &=
0xfff;". Use the proper API for this.Signed-off-by Rasmus Villemoes <[email protected]>
Quoted 9 lines · Lars-Peter Clausen
Quoted 5 lines · Rasmus Villemoes
The intention is obviously to sign-extend a 12 bit quantity. But because of C's promotion rules, the assignment is equivalent to "val16 &=
0xfff;". Use the proper API for this.Signed-off-by Rasmus Villemoes <[email protected]>
Applied to the fixes-togreg branch of iio.git and cc'd to stable.