Skip to content

Commit 19e353f

Browse files
Villemoesjic23
authored andcommitted
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 <linux@rasmusvillemoes.dk> Acked-by: Lars-Peter Clausen <lars@metafoo.de> Cc: Stable@vger.kernel.org Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent f7067a5 commit 19e353f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎drivers/iio/imu/adis16400_core.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/list.h>
2727
#include <linux/module.h>
2828
#include <linux/debugfs.h>
29+
#include <linux/bitops.h>
2930

3031
#include <linux/iio/iio.h>
3132
#include <linux/iio/sysfs.h>
@@ -414,7 +415,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
414415
mutex_unlock(&indio_dev->mlock);
415416
if (ret)
416417
return ret;
417-
val16 = ((val16 & 0xFFF) << 4) >> 4;
418+
val16 = sign_extend32(val16, 11);
418419
*val = val16;
419420
return IIO_VAL_INT;
420421
case IIO_CHAN_INFO_OFFSET:

0 commit comments

Comments
 (0)