drivers/sensor/fxas21002: Fix race condition during initialization
A race condition was identified during the initialization of the driver when the trigger function is enabled. This exposed two issues: 1 - The fxas21002_handle_int is trying to acquire the semaphore before it gets initialized. To solve this we need to initialize the semaphore before calling the fxas21002_trigger_init function. 2 - During the fxas21002_trigger initialization the i2c bus is used (from fxas21002_handle_int function) at the same time as the fxas21002_set_power is being called. To fix this we need to initialize the semaphore with 0 and just release it after calling the fxas21002_set_power function in the fxas21002_int Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
This commit is contained in:
parent
ed4f0ff36e
commit
72cad66c5b
1 changed files with 3 additions and 3 deletions
|
@ -245,6 +245,8 @@ static int fxas21002_init(struct device *dev)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
k_sem_init(&data->sem, 0, UINT_MAX);
|
||||||
|
|
||||||
#if CONFIG_FXAS21002_TRIGGER
|
#if CONFIG_FXAS21002_TRIGGER
|
||||||
if (fxas21002_trigger_init(dev)) {
|
if (fxas21002_trigger_init(dev)) {
|
||||||
SYS_LOG_ERR("Could not initialize interrupts");
|
SYS_LOG_ERR("Could not initialize interrupts");
|
||||||
|
@ -263,9 +265,7 @@ static int fxas21002_init(struct device *dev)
|
||||||
FXAS21002_POWER_ACTIVE,
|
FXAS21002_POWER_ACTIVE,
|
||||||
config->dr);
|
config->dr);
|
||||||
k_busy_wait(transition_time);
|
k_busy_wait(transition_time);
|
||||||
|
k_sem_give(&data->sem);
|
||||||
|
|
||||||
k_sem_init(&data->sem, 1, UINT_MAX);
|
|
||||||
|
|
||||||
SYS_LOG_DBG("Init complete");
|
SYS_LOG_DBG("Init complete");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue