drivers: sensor: bmg160: check gpio calls return code
Some GPIO related calls were not being checked for error. This patch also fixes coverity issue 236651. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
7e57a8720d
commit
50a31d2f36
1 changed files with 19 additions and 11 deletions
|
@ -18,14 +18,14 @@ extern struct bmg160_device_data bmg160_data;
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_DECLARE(BMG160, CONFIG_SENSOR_LOG_LEVEL);
|
LOG_MODULE_DECLARE(BMG160, CONFIG_SENSOR_LOG_LEVEL);
|
||||||
|
|
||||||
static inline void setup_int(const struct device *dev,
|
static inline int setup_int(const struct device *dev,
|
||||||
bool enable)
|
bool enable)
|
||||||
{
|
{
|
||||||
struct bmg160_device_data *data = dev->data;
|
struct bmg160_device_data *data = dev->data;
|
||||||
const struct bmg160_device_config *const cfg =
|
const struct bmg160_device_config *const cfg =
|
||||||
dev->config;
|
dev->config;
|
||||||
|
|
||||||
gpio_pin_interrupt_configure(data->gpio,
|
return gpio_pin_interrupt_configure(data->gpio,
|
||||||
cfg->int_pin,
|
cfg->int_pin,
|
||||||
enable
|
enable
|
||||||
? GPIO_INT_EDGE_TO_ACTIVE
|
? GPIO_INT_EDGE_TO_ACTIVE
|
||||||
|
@ -208,6 +208,7 @@ int bmg160_trigger_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct bmg160_device_config *cfg = dev->config;
|
const struct bmg160_device_config *cfg = dev->config;
|
||||||
struct bmg160_device_data *bmg160 = dev->data;
|
struct bmg160_device_data *bmg160 = dev->data;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* set INT1 pin to: push-pull, active low */
|
/* set INT1 pin to: push-pull, active low */
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_INT_EN1, 0) < 0) {
|
if (bmg160_write_byte(dev, BMG160_REG_INT_EN1, 0) < 0) {
|
||||||
|
@ -257,12 +258,19 @@ int bmg160_trigger_init(const struct device *dev)
|
||||||
bmg160->work.handler = bmg160_work_cb;
|
bmg160->work.handler = bmg160_work_cb;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gpio_pin_configure(bmg160->gpio, cfg->int_pin,
|
ret = gpio_pin_configure(bmg160->gpio, cfg->int_pin,
|
||||||
cfg->int_flags | GPIO_INT_EDGE_TO_ACTIVE);
|
cfg->int_flags | GPIO_INT_EDGE_TO_ACTIVE);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
gpio_init_callback(&bmg160->gpio_cb, bmg160_gpio_callback,
|
gpio_init_callback(&bmg160->gpio_cb, bmg160_gpio_callback,
|
||||||
BIT(cfg->int_pin));
|
BIT(cfg->int_pin));
|
||||||
gpio_add_callback(bmg160->gpio, &bmg160->gpio_cb);
|
|
||||||
setup_int(dev, true);
|
|
||||||
|
|
||||||
return 0;
|
ret = gpio_add_callback(bmg160->gpio, &bmg160->gpio_cb);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return setup_int(dev, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue