Commit 3295f7c5 authored by Fabian Barraez's avatar Fabian Barraez Committed by Benjamin Cabé
Browse files

drivers: sensor: si7060: fix: insecure data handling caught by coverity



- Checking each retval from read register before continue

Signed-off-by: default avatarFabian Barraez <fabianbarraez@gmail.com>
parent 0b843be9
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -58,14 +58,19 @@ static int si7060_sample_fetch(const struct device *dev,
	uint8_t dspsigl;

	retval = si7060_reg_read(dev, SI7060_REG_TEMP_HIGH, &dspsigm);
	retval += si7060_reg_read(dev, SI7060_REG_TEMP_LOW, &dspsigl);
	if (retval != 0) {
		LOG_ERR("Error reading temperature high register");
		return retval;
	}

	retval = si7060_reg_read(dev, SI7060_REG_TEMP_LOW, &dspsigl);
	if (retval != 0) {
		LOG_ERR("Error reading temperature low register");
		return retval;
	}

	if (retval == 0) {
	drv_data->temperature = (256 * (dspsigm & SIGN_BIT_MASK))
	+ dspsigl;
	} else {
		LOG_ERR("Read register err");
	}

	LOG_DBG("Sample_fetch retval: %d", retval);