Skip to content

Commit 7e23a18

Browse files
thomzachkartben
authored andcommitted
drivers: sensor: scd4x: fix int overflow on val2 for temp and hum
The scd4x_channel_get function converts raw word values to struct sensor_value's per the datasheet. The calculation for val2 of a struct sensor_value `val->val2 = ((tmp_val % 0xFFFF) * 1000000) / 0xFFFF;` can overflow the max of int32_t, resulting in an incorrect sensor_value. Fix it by changing the type of tmp_val to int64_t. Signed-off-by: Zach Thomas <[email protected]>
1 parent 097fcb8 commit 7e23a18

File tree

1 file changed

+1
-1
lines changed
  • drivers/sensor/sensirion/scd4x

1 file changed

+1
-1
lines changed

drivers/sensor/sensirion/scd4x/scd4x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static int scd4x_channel_get(const struct device *dev, enum sensor_channel chan,
630630
struct sensor_value *val)
631631
{
632632
const struct scd4x_data *data = dev->data;
633-
int32_t tmp_val;
633+
int64_t tmp_val;
634634

635635
switch ((enum sensor_channel)chan) {
636636
case SENSOR_CHAN_AMBIENT_TEMP:

0 commit comments

Comments
 (0)