Skip to content

Commit b8ce176

Browse files
ceolinkartben
authored andcommitted
pm: policy: Fix possible undefined reference
When PM_POLICY_DEVICE_CONSTRAINTS is enabled, we create a list of devices with the property “zephyr,disabling-power-states” and their respective states to lock. However, if a device is declared but not built (e.g., due to a Kconfig option), we have an undefined reference. This PR changes the code to use the device name instead of the reference. This increases lookup time (which could be cached at runtime), and we still have an entry for a non-existent device. Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 89c29a9 commit b8ce176

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

subsys/pm/policy/policy_device_lock.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <zephyr/pm/device.h>
1212

1313
struct pm_state_device_constraint {
14-
const struct device *const dev;
14+
const char *const dev;
1515
size_t pm_constraints_size;
1616
struct pm_state_constraint *constraints;
1717
};
@@ -71,7 +71,7 @@ DT_FOREACH_STATUS_OKAY_NODE(DEVICE_CONSTRAINTS_DEFINE)
7171
*/
7272
#define PM_STATE_DEVICE_CONSTRAINT_INIT(node_id) \
7373
{ \
74-
.dev = DEVICE_DT_GET(node_id), \
74+
.dev = DEVICE_DT_NAME(node_id), \
7575
.pm_constraints_size = DT_PROP_LEN(node_id, zephyr_disabling_power_states), \
7676
.constraints = PM_CONSTRAINTS_NAME(node_id), \
7777
},
@@ -91,7 +91,9 @@ void pm_policy_device_power_lock_get(const struct device *dev)
9191
{
9292
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_power_state)
9393
for (size_t i = 0; i < ARRAY_SIZE(_devices_constraints); i++) {
94-
if (_devices_constraints[i].dev == dev) {
94+
const struct device *device = device_get_binding(_devices_constraints[i].dev);
95+
96+
if ((device != NULL) && (device == dev)) {
9597
for (size_t j = 0; j < _devices_constraints[i].pm_constraints_size; j++) {
9698
pm_policy_state_lock_get(
9799
_devices_constraints[i].constraints[j].state,
@@ -107,7 +109,9 @@ void pm_policy_device_power_lock_put(const struct device *dev)
107109
{
108110
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_power_state)
109111
for (size_t i = 0; i < ARRAY_SIZE(_devices_constraints); i++) {
110-
if (_devices_constraints[i].dev == dev) {
112+
const struct device *device = device_get_binding(_devices_constraints[i].dev);
113+
114+
if ((device != NULL) && (device == dev)) {
111115
for (size_t j = 0; j < _devices_constraints[i].pm_constraints_size; j++) {
112116
pm_policy_state_lock_put(
113117
_devices_constraints[i].constraints[j].state,

0 commit comments

Comments
 (0)