Commit 0f0f6306 authored by Adam Rizkalla's avatar Adam Rizkalla Committed by Jonathan Cameron

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: default avatarAdam Rizkalla <ajarizzo@gmail.com>
Tested-By: default avatarVasileios Amoiridis <vassilisamir@gmail.com>
Acked-by: default avatarAngel Iglesias <ang.iglesiasg@gmail.com>
Link: https://lore.kernel.org/r/Zin2udkXRD0+GrML@adam-asahi.lan
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 72d0a20f
......@@ -1394,12 +1394,12 @@ static int bmp580_read_temp(struct bmp280_data *data, int *val, int *val2)
/*
* Temperature is returned in Celsius degrees in fractional
* form down 2^16. We rescale by x1000 to return milli Celsius
* to respect IIO ABI.
* form down 2^16. We rescale by x1000 to return millidegrees
* Celsius to respect IIO ABI.
*/
*val = raw_temp * 1000;
*val2 = 16;
return IIO_VAL_FRACTIONAL_LOG2;
raw_temp = sign_extend32(raw_temp, 23);
*val = ((s64)raw_temp * 1000) / (1 << 16);
return IIO_VAL_INT;
}
static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment