[patch] iio: imu: adis16400: Fix sign extension

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Because of C's type promotion rules, the code shifts in
"((val16 & 0xFFF) << 4) >> 4;" cancel each other out and they're a
no-op.

The intention here was to sign-extend then 11th bit so we can use the
sign_extend32() function.

Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
---
Please review this carefully.  I'm pretty sure it's correct but this is
the first time I've ever used the sign_extend32() function.

diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index b70873d..ed636c9 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -414,7 +414,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:
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux