Skip to content

Commit 9930c34

Browse files
carlocaionenashif
authored andcommitted
pm: policy: Selectively compile on "zephyr,power-state" compatible
Coverity is complaining: CID 316017: Control flow issues (NO_EFFECT) >>> This less-than-zero comparison of an unsigned value is never true. 148 for (size_t i = 0; i < ARRAY_SIZE(substate_lock_t); i++) { This is a false positive but we can still optimize the code and making coverity happy by simply avoiding compiling the offending code when no power states are defined into the DT. Signed-off-by: Carlo Caione <[email protected]>
1 parent 208908e commit 9930c34

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

subsys/pm/policy.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <zephyr/sys/atomic.h>
1616
#include <zephyr/toolchain.h>
1717

18+
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_power_state)
19+
1820
#define DT_SUB_LOCK_INIT(node_id) \
1921
{ .state = PM_STATE_DT_INIT(node_id), \
2022
.substate_id = DT_PROP_OR(node_id, substate_id, 0), \
@@ -40,6 +42,8 @@ static struct {
4042
DT_FOREACH_STATUS_OKAY(zephyr_power_state, DT_SUB_LOCK_INIT)
4143
};
4244

45+
#endif
46+
4347
/** Lock to synchronize access to the latency request list. */
4448
static struct k_spinlock latency_lock;
4549
/** List of maximum latency requests. */
@@ -189,17 +193,20 @@ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
189193

190194
void pm_policy_state_lock_get(enum pm_state state, uint8_t substate_id)
191195
{
196+
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_power_state)
192197
for (size_t i = 0; i < ARRAY_SIZE(substate_lock_t); i++) {
193198
if (substate_lock_t[i].state == state &&
194199
(substate_lock_t[i].substate_id == substate_id ||
195200
substate_id == PM_ALL_SUBSTATES)) {
196201
atomic_inc(&substate_lock_t[i].lock);
197202
}
198203
}
204+
#endif
199205
}
200206

201207
void pm_policy_state_lock_put(enum pm_state state, uint8_t substate_id)
202208
{
209+
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_power_state)
203210
for (size_t i = 0; i < ARRAY_SIZE(substate_lock_t); i++) {
204211
if (substate_lock_t[i].state == state &&
205212
(substate_lock_t[i].substate_id == substate_id ||
@@ -211,17 +218,20 @@ void pm_policy_state_lock_put(enum pm_state state, uint8_t substate_id)
211218
__ASSERT(cnt >= 1, "Unbalanced state lock get/put");
212219
}
213220
}
221+
#endif
214222
}
215223

216224
bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t substate_id)
217225
{
226+
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_power_state)
218227
for (size_t i = 0; i < ARRAY_SIZE(substate_lock_t); i++) {
219228
if (substate_lock_t[i].state == state &&
220229
(substate_lock_t[i].substate_id == substate_id ||
221230
substate_id == PM_ALL_SUBSTATES)) {
222231
return (atomic_get(&substate_lock_t[i].lock) != 0);
223232
}
224233
}
234+
#endif
225235

226236
return false;
227237
}

0 commit comments

Comments
 (0)