iio: imu: adis16400: Fix sign extension
Subsystems (3)
PATCH 1/1 iio: imu: adis16400: Fix sign extension
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.
---
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.
drivers/iio/imu/adis16400_core.c +1 -1
@@ -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 :
Quoted 11 lines · Dan Carpenter
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 <[email protected]>---
Please review this carefully. I'm pretty sure it's correct but this is the first time I've ever used thesign_extend32()function.
Hi,
Rasmus already fixed this a couple of days ago.
Thanks,
- Lars
Quoted 13 lines · Lars-Peter Clausen
Quoted 11 lines · Dan Carpenter
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 <[email protected]>---
Please review this carefully. I'm pretty sure it's correct but this is the first time I've ever used thesign_extend32()function.
Quoted 6 lines
Hi,
Rasmus already fixed this a couple of days ago.
Thanks,
- Lars
Oh. Good. I was CC'd on the other one that he fixed so I went looking for other bugs and I found this one.
Rasmus, are you using a static checker? Which one?
regards,
dan carpenter
Quoted 1 line · Dan Carpenter
Rasmus, are you using a static checker? Which one?
Sort of:
https://github.com/Villemoes/linux-cocci/blob/master/misc/sign_extend.cocci
Rasmus
Quoted 8 lines · Rasmus Villemoes
Quoted 1 line · Dan Carpenter
Rasmus, are you using a static checker? Which one?
Sort of:
https://github.com/Villemoes/linux-cocci/blob/master/misc/sign_extend.cocci
Did you find the bug in fm10k_update_xc_addr_pf()? That's the other bug I found.
regards,
dan carpenter