drivers: sensor: adt7420: check gpio add callback return code

gpio_add_callback was not being error-checked. Some other minor cleanups
(rc var to the top, remove redundant log).

This patch fixes coverity issue 236649.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-08-26 08:41:08 +02:00 committed by Anas Nashif
parent 2682879df5
commit 6cfab29e19

View file

@ -130,6 +130,7 @@ int adt7420_init_interrupt(const struct device *dev)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;
int rc;
drv_data->gpio = device_get_binding(cfg->int_name);
if (drv_data->gpio == NULL) {
@ -142,14 +143,14 @@ int adt7420_init_interrupt(const struct device *dev)
adt7420_gpio_callback,
BIT(cfg->int_pin));
int rc = gpio_pin_configure(drv_data->gpio, cfg->int_pin,
GPIO_INPUT | cfg->int_flags);
if (rc == 0) {
gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
rc = gpio_pin_configure(drv_data->gpio, cfg->int_pin,
GPIO_INPUT | cfg->int_flags);
if (rc < 0) {
return rc;
}
if (rc != 0) {
LOG_DBG("Failed to set gpio callback!");
rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
if (rc < 0) {
return rc;
}