drivers: w1: fix return check in bit_read for w1-gpio

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 <thomas.stranger@outlook.com>
This commit is contained in:
Thomas Stranger 2024-02-04 20:08:50 +01:00 committed by Fabio Baltieri
parent 199487be54
commit 505cc19941

View file

@ -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:
@ -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: