Skip to content

Commit 712dff5

Browse files
jeffwelder-ellenbytechkartben
authored andcommitted
drivers: sensor: lsm6dsv16x: fix temperature overflow
Fixed integer overflow by explicit casting Signed-off-by: Jeff Welder <[email protected]>
1 parent 0fd662f commit 712dff5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/sensor/st/lsm6dsv16x/lsm6dsv16x.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,14 @@ static int lsm6dsv16x_gyro_channel_get(enum sensor_channel chan,
722722
static void lsm6dsv16x_gyro_channel_get_temp(struct sensor_value *val,
723723
struct lsm6dsv16x_data *data)
724724
{
725-
int32_t micro_c;
726-
727725
/* convert units to micro Celsius. Raw temperature samples are
728726
* expressed in 256 LSB/deg_C units. And LSB output is 0 at 25 C.
729727
*/
730-
micro_c = (data->temp_sample * 1000000) / 256;
728+
int64_t temp_sample = data->temp_sample;
729+
int64_t micro_c = (temp_sample * 1000000LL) / 256;
731730

732-
val->val1 = micro_c / 1000000 + 25;
733-
val->val2 = micro_c % 1000000;
731+
val->val1 = (int32_t)(micro_c / 1000000) + 25;
732+
val->val2 = (int32_t)(micro_c % 1000000);
734733
}
735734
#endif
736735

0 commit comments

Comments
 (0)