Commit 0e925701 authored by Brett Witherspoon's avatar Brett Witherspoon Committed by Maureen Helm
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: default avatarBrett Witherspoon <spoonb@cdspooner.com>
parent 6746470d
Loading
Loading
Loading
Loading
+3 −14
Original line number Diff line number Diff line
@@ -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,8 +41,6 @@ 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,
@@ -51,9 +48,6 @@ static void adxl362_gpio_callback(struct device *dev,
{
	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;
}