Skip to content

Commit 0f0f630

Browse files
ARizzo35jic23
authored andcommitted
iio: pressure: bmp280: Fix BMP580 temperature reading
Fix overflow issue when storing BMP580 temperature reading and properly preserve sign of 24-bit data. Signed-off-by: Adam Rizkalla <ajarizzo@gmail.com> Tested-By: Vasileios Amoiridis <vassilisamir@gmail.com> Acked-by: Angel Iglesias <ang.iglesiasg@gmail.com> Link: https://lore.kernel.org/r/Zin2udkXRD0+GrML@adam-asahi.lan Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 72d0a20 commit 0f0f630

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/iio/pressure/bmp280-core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,12 +1394,12 @@ static int bmp580_read_temp(struct bmp280_data *data, int *val, int *val2)
13941394

13951395
/*
13961396
* Temperature is returned in Celsius degrees in fractional
1397-
* form down 2^16. We rescale by x1000 to return milli Celsius
1398-
* to respect IIO ABI.
1397+
* form down 2^16. We rescale by x1000 to return millidegrees
1398+
* Celsius to respect IIO ABI.
13991399
*/
1400-
*val = raw_temp * 1000;
1401-
*val2 = 16;
1402-
return IIO_VAL_FRACTIONAL_LOG2;
1400+
raw_temp = sign_extend32(raw_temp, 23);
1401+
*val = ((s64)raw_temp * 1000) / (1 << 16);
1402+
return IIO_VAL_INT;
14031403
}
14041404

14051405
static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2)

0 commit comments

Comments
 (0)