drivers: sensor: lsm6dsv16x: fix temperature overflow

Fixed integer overflow by explicit casting

Signed-off-by: Jeff Welder <Jeff.Welder@ellenbytech.com>
This commit is contained in:
Jeff Welder 2024-10-21 11:42:58 -04:00 committed by Benjamin Cabé
commit 712dff57d8

View file

@ -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