From c3050a5aab1e86d02642eb4c6a027419e6a3a096 Mon Sep 17 00:00:00 2001 From: Armando Visconti Date: Fri, 3 Sep 2021 18:17:05 +0200 Subject: [PATCH] drivers/sensor: lps22hh: Fix int32 overflow in the val2 part The val2 calculation was done using (1000000 / 40960) as multiplying factor, which was sometimes leading to a int32 overflow. So, let's use the equivalent (but smaller) (3125 / 128). Fix #38090 Signed-off-by: Armando Visconti --- drivers/sensor/lps22hh/lps22hh.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/sensor/lps22hh/lps22hh.c b/drivers/sensor/lps22hh/lps22hh.c index fae2269fef7..ba41cbefb1e 100644 --- a/drivers/sensor/lps22hh/lps22hh.c +++ b/drivers/sensor/lps22hh/lps22hh.c @@ -62,7 +62,11 @@ static inline void lps22hh_press_convert(struct sensor_value *val, /* Also convert hPa into kPa */ val->val1 = press_tmp / 40960; - val->val2 = (press_tmp % 40960) * 1000000 / 40960; + + /* For the decimal part use (3125 / 128) as a factor instead of + * (1000000 / 40960) to avoid int32 overflow + */ + val->val2 = (press_tmp % 40960) * 3125 / 128; } static inline void lps22hh_temp_convert(struct sensor_value *val,