Commit dac99fda authored by Rasmus Villemoes's avatar Rasmus Villemoes Committed by Jiri Slaby

iio: imu: adis16400: Fix sign extension

commit 19e353f2 upstream.

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: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent 93ba6108
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/bitops.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -447,7 +448,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, ...@@ -447,7 +448,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
if (ret) if (ret)
return ret; return ret;
val16 = ((val16 & 0xFFF) << 4) >> 4; val16 = sign_extend32(val16, 11);
*val = val16; *val = val16;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
......
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