pm: device_runtime: Fix reference count when action fails
The usage count and device power state has to be restored when the device action callback fails in the async operation. Otherwise it will lead to an inconsistent state. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
9698d1f1a1
commit
ce170fa029
1 changed files with 4 additions and 1 deletions
|
@ -86,7 +86,10 @@ static void runtime_suspend_work(struct k_work *work)
|
||||||
ret = pm->action_cb(pm->dev, PM_DEVICE_ACTION_SUSPEND);
|
ret = pm->action_cb(pm->dev, PM_DEVICE_ACTION_SUSPEND);
|
||||||
|
|
||||||
(void)k_mutex_lock(&pm->lock, K_FOREVER);
|
(void)k_mutex_lock(&pm->lock, K_FOREVER);
|
||||||
if (ret == 0) {
|
if (ret < 0) {
|
||||||
|
pm->usage++;
|
||||||
|
pm->state = PM_DEVICE_STATE_ACTIVE;
|
||||||
|
} else {
|
||||||
pm->state = PM_DEVICE_STATE_SUSPENDED;
|
pm->state = PM_DEVICE_STATE_SUSPENDED;
|
||||||
}
|
}
|
||||||
k_condvar_broadcast(&pm->condvar);
|
k_condvar_broadcast(&pm->condvar);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue