pm: device_runtime: Keep enable behavior consistent

It is not possible to rely on pm->dev to do lazy initialization of
some components. For example, in the follow sequence of commands:

1 - pm_device_runtime_enable()
  pm->state == PM_DEVICE_STATE_SUSPENDED;
2 - pm_device_runtime_disable()
  pm->state == PM_DEVICE_STATE_ACTIVE;
3 - pm_device_runtime_enable()
  pm->state == PM_DEVICE_STATE_ACTIVE

After the first time pm_device_runtime_enable(), the device state will
be suspended, but after the second time this function executes the state
will be active. That is not consistent.

It is just easier to remove the branch check and always set those
fields for the sake of consistent.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2021-12-10 12:50:35 -08:00 committed by Anas Nashif
commit a6d34becb5

View file

@ -183,9 +183,9 @@ void pm_device_runtime_enable(const struct device *dev)
/* lazy init of PM fields */
if (pm->dev == NULL) {
pm->dev = dev;
pm->state = PM_DEVICE_STATE_SUSPENDED;
k_work_init_delayable(&pm->work, runtime_suspend_work);
}
pm->state = PM_DEVICE_STATE_SUSPENDED;
atomic_set_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_ENABLED);