drivers: sensor: adxl362: improve error handling

Error handling was missing in numerous places, mostly on GPIO related
callbacks. Some error codes were not correct (-EINVAL vs -ENODEV) and in
some cases error was not propagated correctly.

Fixes #38117

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-08-30 20:50:09 +02:00 committed by Anas Nashif
parent 35e7acb703
commit 5f9fddd9d5

View file

@ -124,24 +124,26 @@ int adxl362_init_interrupt(const struct device *dev)
if (!device_is_ready(cfg->interrupt.port)) {
LOG_ERR("GPIO port %s not ready", cfg->interrupt.port->name);
return -EINVAL;
return -ENODEV;
}
ret = adxl362_set_interrupt_mode(dev, CONFIG_ADXL362_INTERRUPT_MODE);
if (ret) {
return -EFAULT;
if (ret < 0) {
return ret;
}
gpio_pin_configure_dt(&cfg->interrupt, GPIO_INPUT);
ret = gpio_pin_configure_dt(&cfg->interrupt, GPIO_INPUT);
if (ret < 0) {
return ret;
}
gpio_init_callback(&drv_data->gpio_cb,
adxl362_gpio_callback,
BIT(cfg->interrupt.pin));
if (gpio_add_callback(cfg->interrupt.port, &drv_data->gpio_cb) < 0) {
LOG_ERR("Failed to set gpio callback!");
return -EIO;
ret = gpio_add_callback(cfg->interrupt.port, &drv_data->gpio_cb);
if (ret < 0) {
return ret;
}
drv_data->dev = dev;
@ -158,7 +160,11 @@ int adxl362_init_interrupt(const struct device *dev)
drv_data->work.handler = adxl362_work_cb;
#endif
gpio_pin_interrupt_configure_dt(&cfg->interrupt, GPIO_INT_EDGE_TO_ACTIVE);
ret = gpio_pin_interrupt_configure_dt(&cfg->interrupt,
GPIO_INT_EDGE_TO_ACTIVE);
if (ret < 0) {
return ret;
}
return 0;
}