diff options
| author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2015-01-22 18:09:56 -0500 |
|---|---|---|
| committer | Jonathan Cameron <jic23@kernel.org> | 2015-01-26 16:04:27 -0500 |
| commit | f7067a5ad717d4dbb4faa3ec56744152f6ba97ad (patch) | |
| tree | f1d5da341b0f9d7d8b7a26b1ba0fafd913bb2a13 | |
| parent | 89bb35e200bee745c539a96666e0792301ca40f1 (diff) | |
staging: iio: ad2s1200: Fix sign extension
The line above makes vel a 12-bit quantity (st->rx[] is u8). The
intention is to sign-extend vel using bit 11 as the sign bit. But
because of C's promotion rules "vel = (vel << 4) >> 4;" is actually a
no-op, since vel is promoted to int before the inner
shift. sign_extend32 works equally well for 8 and 16 bits types, so
use that.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
| -rw-r--r-- | drivers/staging/iio/resolver/ad2s1200.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/staging/iio/resolver/ad2s1200.c b/drivers/staging/iio/resolver/ad2s1200.c index 017d2f8379b7..c17893b4918c 100644 --- a/drivers/staging/iio/resolver/ad2s1200.c +++ b/drivers/staging/iio/resolver/ad2s1200.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
| 19 | #include <linux/gpio.h> | 19 | #include <linux/gpio.h> |
| 20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 21 | #include <linux/bitops.h> | ||
| 21 | 22 | ||
| 22 | #include <linux/iio/iio.h> | 23 | #include <linux/iio/iio.h> |
| 23 | #include <linux/iio/sysfs.h> | 24 | #include <linux/iio/sysfs.h> |
| @@ -68,7 +69,7 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev, | |||
| 68 | break; | 69 | break; |
| 69 | case IIO_ANGL_VEL: | 70 | case IIO_ANGL_VEL: |
| 70 | vel = (((s16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); | 71 | vel = (((s16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); |
| 71 | vel = (vel << 4) >> 4; | 72 | vel = sign_extend32(vel, 11); |
| 72 | *val = vel; | 73 | *val = vel; |
| 73 | break; | 74 | break; |
| 74 | default: | 75 | default: |
