Skip to content

Commit 2174ea0

Browse files
jilaypandyakartben
authored andcommitted
drivers: sensor: apds9306 fix unchecked return value coverity issue
check the return valeus of i2c_reg_write_byte_dt function and return appropriate error code Signed-off-by: Jilay Pandya <[email protected]>
1 parent f7bae12 commit 2174ea0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/sensor/apds9306/apds9306.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ static int apds9306_sensor_setup(const struct device *dev)
271271
/* Wait for the device to become ready after a possible power cycle. */
272272
now = k_uptime_get_32();
273273
do {
274-
i2c_reg_read_byte_dt(&config->i2c, APDS9306_REGISTER_MAIN_STATUS, &temp);
274+
if (i2c_reg_read_byte_dt(&config->i2c, APDS9306_REGISTER_MAIN_STATUS, &temp)) {
275+
LOG_ERR("Failed reading sensor status!");
276+
return -EFAULT;
277+
}
275278

276279
/* We wait 100 ms maximum for the device to become ready. */
277280
if ((k_uptime_get_32() - now) > 100) {
@@ -308,7 +311,10 @@ static int apds9306_sensor_setup(const struct device *dev)
308311

309312
/* Perform a dummy read to avoid bus errors after the reset. See */
310313
/* https://lore.kernel.org/lkml/[email protected]/ */
311-
i2c_reg_read_byte_dt(&config->i2c, APDS9306_REGISTER_PART_ID, &temp);
314+
if (i2c_reg_read_byte_dt(&config->i2c, APDS9306_REGISTER_PART_ID, &temp)) {
315+
LOG_ERR("Failed reading chip id!");
316+
return -EFAULT;
317+
}
312318

313319
return 0;
314320
}

0 commit comments

Comments
 (0)