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:
Flavio Ceolin 2022-01-07 23:24:50 -08:00 committed by Anas Nashif
commit ce170fa029

View file

@ -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);