pm: device_runtime: balanced power domain operations

Only run `pm_device_runtime_put` on the dependent domain if the original
claim operation succeeded. This fixes unbalanced operations when running
```
pm_device_runtime_get(dev);
pm_device_runtime_put(dev);
```
On a device that does not have PM enabled but does have a power domain.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2023-03-26 14:01:37 +10:00 committed by Anas Nashif
parent 4b2da59de5
commit 2ef95ecd8f
2 changed files with 6 additions and 1 deletions

View file

@ -32,6 +32,8 @@ enum pm_device_flag {
PM_DEVICE_FLAG_BUSY,
/** Indicate if the device failed to power up. */
PM_DEVICE_FLAG_TURN_ON_FAILED,
/** Indicate if the device has claimed a power domain */
PM_DEVICE_FLAG_PD_CLAIMED,
/**
* Indicates whether or not the device is capable of waking the system
* up.

View file

@ -163,6 +163,8 @@ int pm_device_runtime_get(const struct device *dev)
ret = -EAGAIN;
goto unlock;
}
/* Power domain successfully claimed */
atomic_set_bit(&pm->flags, PM_DEVICE_FLAG_PD_CLAIMED);
}
pm->usage++;
@ -216,7 +218,8 @@ int pm_device_runtime_put(const struct device *dev)
/*
* Now put the domain
*/
if ((ret == 0) && PM_DOMAIN(dev->pm) != NULL) {
if ((ret == 0) &&
atomic_test_and_clear_bit(&dev->pm->flags, PM_DEVICE_FLAG_PD_CLAIMED)) {
ret = pm_device_runtime_put(PM_DOMAIN(dev->pm));
}
SYS_PORT_TRACING_FUNC_EXIT(pm, device_runtime_put, dev, ret);