From 6cfab29e190e7baee82f878d99311a700e711b0c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 26 Aug 2021 08:41:08 +0200 Subject: [PATCH] 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 --- drivers/sensor/adt7420/adt7420_trigger.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/adt7420/adt7420_trigger.c b/drivers/sensor/adt7420/adt7420_trigger.c index fa75c8908fa..0affa74b7bf 100644 --- a/drivers/sensor/adt7420/adt7420_trigger.c +++ b/drivers/sensor/adt7420/adt7420_trigger.c @@ -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; }