Re: [PATCH] staging: iio: ad2s1200: Fix sign extension

2015-01-26 Thread Jonathan Cameron
On 23/01/15 08:56, Lars-Peter Clausen wrote: > On 01/23/2015 12:09 AM, Rasmus Villemoes wrote: >> 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 actua

Re: [PATCH] staging: iio: ad2s1200: Fix sign extension

2015-01-23 Thread Lars-Peter Clausen
On 01/23/2015 12:09 AM, Rasmus Villemoes wrote: 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 i

[PATCH] staging: iio: ad2s1200: Fix sign extension

2015-01-22 Thread Rasmus Villemoes
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