From 2682879df547c7cc6fa8877fbc944a2ab5870b77 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 26 Aug 2021 08:38:16 +0200 Subject: [PATCH] drivers: sensor: sx9500: check gpio calls return code Some GPIO related calls were not being checked for error. This patch fixes coverity issue 236648. Signed-off-by: Gerard Marull-Paretas --- drivers/sensor/sx9500/sx9500_trigger.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/sx9500/sx9500_trigger.c b/drivers/sensor/sx9500/sx9500_trigger.c index ac1d60c402a..f9dfd4ddc8a 100644 --- a/drivers/sensor/sx9500/sx9500_trigger.c +++ b/drivers/sensor/sx9500/sx9500_trigger.c @@ -131,6 +131,7 @@ int sx9500_setup_interrupt(const struct device *dev) { struct sx9500_data *data = dev->data; const struct device *gpio; + int ret; #ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD k_sem_init(&data->sem, 0, K_SEM_MAX_LIMIT); @@ -147,16 +148,26 @@ int sx9500_setup_interrupt(const struct device *dev) return -EINVAL; } - gpio_pin_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios), - GPIO_INPUT | DT_INST_GPIO_FLAGS(0, int_gpios)); + ret = gpio_pin_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios), + GPIO_INPUT | DT_INST_GPIO_FLAGS(0, int_gpios)); + if (ret < 0) { + return ret; + } gpio_init_callback(&data->gpio_cb, sx9500_gpio_cb, BIT(DT_INST_GPIO_PIN(0, int_gpios))); - gpio_add_callback(gpio, &data->gpio_cb); - gpio_pin_interrupt_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios), - GPIO_INT_EDGE_TO_ACTIVE); + ret = gpio_add_callback(gpio, &data->gpio_cb); + if (ret < 0) { + return ret; + } + + ret = gpio_pin_interrupt_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios), + GPIO_INT_EDGE_TO_ACTIVE); + if (ret < 0) { + return ret; + } #ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD k_thread_create(&sx9500_thread, sx9500_thread_stack,