Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Rasmus Villemoes and committed by
Jonathan Cameron
19e353f2 f7067a5a

+2 -1
+2 -1
drivers/iio/imu/adis16400_core.c
··· 26 26 #include <linux/list.h> 27 27 #include <linux/module.h> 28 28 #include <linux/debugfs.h> 29 + #include <linux/bitops.h> 29 30 30 31 #include <linux/iio/iio.h> 31 32 #include <linux/iio/sysfs.h> ··· 415 414 mutex_unlock(&indio_dev->mlock); 416 415 if (ret) 417 416 return ret; 418 - val16 = ((val16 & 0xFFF) << 4) >> 4; 417 + val16 = sign_extend32(val16, 11); 419 418 *val = val16; 420 419 return IIO_VAL_INT; 421 420 case IIO_CHAN_INFO_OFFSET: