Skip to content

Commit 3295f7c

Browse files
fabocodekartben
authored andcommitted
drivers: sensor: si7060: fix: insecure data handling caught by coverity
- Checking each retval from read register before continue Signed-off-by: Fabian Barraez <[email protected]>
1 parent 0b843be commit 3295f7c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/sensor/silabs/si7060/si7060.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ static int si7060_sample_fetch(const struct device *dev,
5858
uint8_t dspsigl;
5959

6060
retval = si7060_reg_read(dev, SI7060_REG_TEMP_HIGH, &dspsigm);
61-
retval += si7060_reg_read(dev, SI7060_REG_TEMP_LOW, &dspsigl);
61+
if (retval != 0) {
62+
LOG_ERR("Error reading temperature high register");
63+
return retval;
64+
}
6265

63-
if (retval == 0) {
64-
drv_data->temperature = (256 * (dspsigm & SIGN_BIT_MASK))
65-
+ dspsigl;
66-
} else {
67-
LOG_ERR("Read register err");
66+
retval = si7060_reg_read(dev, SI7060_REG_TEMP_LOW, &dspsigl);
67+
if (retval != 0) {
68+
LOG_ERR("Error reading temperature low register");
69+
return retval;
6870
}
6971

72+
drv_data->temperature = (256 * (dspsigm & SIGN_BIT_MASK))
73+
+ dspsigl;
74+
7075
LOG_DBG("Sample_fetch retval: %d", retval);
7176

7277
return retval;

0 commit comments

Comments
 (0)