Skip to content
Permalink
Browse files

drivers: adxl362: don't disable callbacks

Enabling and disabling the GPIO callbacks is error prone and unnecessary
since the trigger data is protected with a mutex, so it has been
removed. This resolves the following issues:

- The GPIO callbacks are not being re-enabled properly in the error path
  of the trigger setting function.

- The device pointer used in the GPIO callback to retrieve the ADXL362
  driver configuration data is the GPIO device not the ADXL362 device,
  so this cast is invalid and the int_gpio field is garbage.

- There are potential timing issues between enabling interrupts and
  re-enabling the callbacks.

Signed-off-by: Brett Witherspoon <spoonb@cdspooner.com>
  • Loading branch information...
bwitherspoon authored and MaureenHelm committed May 5, 2019
1 parent 6746470 commit 0e9257018cd5fb9dab916a1e8d3687ef894c1f1c
Showing with 3 additions and 14 deletions.
  1. +3 −14 drivers/sensor/adxl362/adxl362_trigger.c
@@ -20,7 +20,6 @@ static void adxl362_thread_cb(void *arg)
{
struct device *dev = arg;
struct adxl362_data *drv_data = dev->driver_data;
const struct adxl362_config *cfg = dev->config->config_info;
u8_t status_buf;
int ret;

@@ -42,18 +41,13 @@ static void adxl362_thread_cb(void *arg)
drv_data->drdy_handler(dev, &drv_data->drdy_trigger);
}
k_mutex_unlock(&drv_data->trigger_mutex);

gpio_pin_enable_callback(drv_data->gpio, cfg->int_gpio);
}

static void adxl362_gpio_callback(struct device *dev,
struct gpio_callback *cb, u32_t pins)
{
struct adxl362_data *drv_data =
CONTAINER_OF(cb, struct adxl362_data, gpio_cb);
const struct adxl362_config *cfg = dev->config->config_info;

gpio_pin_disable_callback(dev, cfg->int_gpio);

#if defined(CONFIG_ADXL362_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem);
@@ -90,12 +84,9 @@ int adxl362_trigger_set(struct device *dev,
sensor_trigger_handler_t handler)
{
struct adxl362_data *drv_data = dev->driver_data;
const struct adxl362_config *cfg = dev->config->config_info;
u8_t int_mask, int_en, status_buf;
int ret;

gpio_pin_disable_callback(drv_data->gpio, cfg->int_gpio);

switch (trig->type) {
case SENSOR_TRIG_THRESHOLD:
k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER);
@@ -114,8 +105,7 @@ int adxl362_trigger_set(struct device *dev,
break;
default:
LOG_ERR("Unsupported sensor trigger");
ret = -ENOTSUP;
goto out;
return -ENOTSUP;
}

if (handler) {
@@ -133,9 +123,6 @@ int adxl362_trigger_set(struct device *dev,

ret = adxl362_get_status(dev, &status_buf);

out:
gpio_pin_enable_callback(drv_data->gpio, cfg->int_gpio);

return ret;
}

@@ -186,5 +173,7 @@ int adxl362_init_interrupt(struct device *dev)
drv_data->dev = dev;
#endif

gpio_pin_enable_callback(drv_data->gpio, cfg->int_gpio);

return 0;
}

0 comments on commit 0e92570

Please sign in to comment.
You can’t perform that action at this time.