Skip to content

Commit 13ffe9a

Browse files
Colin Ian Kingjic23
authored andcommitted
staging: iio: ade7759: fix signed extension bug on shift of a u8
The current shift of st->rx[2] left shifts a u8 24 bits left, promotes the integer to a an int and then to a unsigned u64. If the top bit of st->rx[2] is set then we end up with all the upper bits being set to 1. Fix this by casting st->rx[2] to a u64 before the 24 bit left shift. Detected by CoverityScan CID#144940 ("Unintended sign extension") Fixes: 2919fa5 ("staging: iio: meter: new driver for ADE7759 devices") Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent f61dfff commit 13ffe9a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/staging/iio/meter/ade7759.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int ade7759_spi_read_reg_40(struct device *dev,
172172
reg_address);
173173
goto error_ret;
174174
}
175-
*val = ((u64)st->rx[1] << 32) | (st->rx[2] << 24) |
175+
*val = ((u64)st->rx[1] << 32) | ((u64)st->rx[2] << 24) |
176176
(st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
177177

178178
error_ret:

0 commit comments

Comments
 (0)