Skip to content

Commit

Permalink
drivers: w1: fix return check in bit_read for w1-gpio
Browse files Browse the repository at this point in the history
The driver masked the return value of a pin read operation before
checking the error.
Thus not detecting a potential error and leading to logically
dead code, which was detected by coverity in CID 340853.
Anther instance XORs 1 before returning, resulting in an unexpected
return value;

Signed-off-by: Thomas Stranger <[email protected]>
  • Loading branch information
str4t0m authored and fabiobaltieri committed Feb 8, 2024
1 parent 199487b commit 505cc19
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/w1/w1_zephyr_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ static int w1_gpio_reset_bus(const struct device *dev)
}

W1_GPIO_WAIT_US(timing->i);
ret = gpio_pin_get_dt(spec) ^ 0x01;
ret = gpio_pin_get_dt(spec);
if (ret < 0) {
goto out;
}
ret ^= 0x01;

W1_GPIO_WAIT_US(timing->j);
out:
Expand Down Expand Up @@ -190,10 +191,11 @@ static int w1_gpio_read_bit(const struct device *dev)
}

W1_GPIO_WAIT_US(timing->e);
ret = gpio_pin_get_dt(spec) & 0x01;
ret = gpio_pin_get_dt(spec);
if (ret < 0) {
goto out;
}
ret &= 0x01;

W1_GPIO_WAIT_US(timing->f);
out:
Expand Down

0 comments on commit 505cc19

Please sign in to comment.