pm: device: use z_device_get_all_static

Use the internal function z_device_get_all_static helper function
instead of using __device_start and __device_end directly. Some other
minor adjustments have been done (e.g. reduce *dev scope to the for
loop). An issue on the range of the for loop in _pm_devices has also
been fixed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-08-04 16:59:26 +02:00 committed by Christopher Friedt
parent 7e7b222d84
commit 8b0d3450a0

View file

@ -14,9 +14,6 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(power);
extern const struct device __device_start[];
extern const struct device __device_end[];
#if defined(CONFIG_PM)
extern const struct device *__pm_device_slots_start[];
@ -25,10 +22,14 @@ static size_t num_susp;
static int _pm_devices(enum pm_device_state state)
{
const struct device *dev;
const struct device *devs;
size_t devc;
devc = z_device_get_all_static(&devs);
num_susp = 0;
for (dev = (__device_end - 1); dev > __device_start; dev--) {
for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) {
int ret;
/* ignore busy devices */
@ -177,13 +178,15 @@ int pm_device_state_get(const struct device *dev,
bool pm_device_is_any_busy(void)
{
const struct device *dev = __device_start;
const struct device *devs;
size_t devc;
while (dev < __device_end) {
devc = z_device_get_all_static(&devs);
for (const struct device *dev = devs; dev < (devs + devc); dev++) {
if (atomic_test_bit(dev->pm->flags, PM_DEVICE_FLAG_BUSY)) {
return true;
}
++dev;
}
return false;