Skip to content

Commit

Permalink
drivers: sensor: lsm6dsv16x: fix temperature overflow
Browse files Browse the repository at this point in the history
Fixed integer overflow by explicit casting

Signed-off-by: Jeff Welder <[email protected]>
  • Loading branch information
jeffwelder-ellenbytech authored and kartben committed Dec 2, 2024
1 parent 0fd662f commit 712dff5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions drivers/sensor/st/lsm6dsv16x/lsm6dsv16x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 712dff5

Please sign in to comment.