From 712dff57d8e8ee0aa9b3e858c678c0ae63622fb3 Mon Sep 17 00:00:00 2001 From: Jeff Welder Date: Mon, 21 Oct 2024 11:42:58 -0400 Subject: [PATCH] drivers: sensor: lsm6dsv16x: fix temperature overflow Fixed integer overflow by explicit casting Signed-off-by: Jeff Welder --- drivers/sensor/st/lsm6dsv16x/lsm6dsv16x.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/st/lsm6dsv16x/lsm6dsv16x.c b/drivers/sensor/st/lsm6dsv16x/lsm6dsv16x.c index 212893d068fac1..f58e3bb1f7a448 100644 --- a/drivers/sensor/st/lsm6dsv16x/lsm6dsv16x.c +++ b/drivers/sensor/st/lsm6dsv16x/lsm6dsv16x.c @@ -722,15 +722,14 @@ static int lsm6dsv16x_gyro_channel_get(enum sensor_channel chan, static void lsm6dsv16x_gyro_channel_get_temp(struct sensor_value *val, struct lsm6dsv16x_data *data) { - int32_t micro_c; - /* convert units to micro Celsius. Raw temperature samples are * expressed in 256 LSB/deg_C units. And LSB output is 0 at 25 C. */ - micro_c = (data->temp_sample * 1000000) / 256; + int64_t temp_sample = data->temp_sample; + int64_t micro_c = (temp_sample * 1000000LL) / 256; - val->val1 = micro_c / 1000000 + 25; - val->val2 = micro_c % 1000000; + val->val1 = (int32_t)(micro_c / 1000000) + 25; + val->val2 = (int32_t)(micro_c % 1000000); } #endif