From 2194069d8d0fb302c1898b0aacbc04766536f959 Mon Sep 17 00:00:00 2001 From: Zhaoxiang Jin Date: Fri, 31 Oct 2025 10:54:21 +0800 Subject: [PATCH] cpu_freq: Validate P-states in devicetree in build time Validate P-states in devicetree in build time. If no P-states are defined, a build error will be raised. Signed-off-by: Zhaoxiang Jin --- subsys/cpu_freq/cpu_freq.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subsys/cpu_freq/cpu_freq.c b/subsys/cpu_freq/cpu_freq.c index 37d19a8462b..4c6d16d4504 100644 --- a/subsys/cpu_freq/cpu_freq.c +++ b/subsys/cpu_freq/cpu_freq.c @@ -12,6 +12,17 @@ LOG_MODULE_REGISTER(cpu_freq, CONFIG_CPU_FREQ_LOG_LEVEL); +/* Build-time validation: require performance_states node with at least one child */ +#define PSTATE_ROOT DT_PATH(performance_states) +#define CPU_FREQ_COUNT_OKAY_CHILD(_node_id) + 1 +enum { CPU_FREQ_PSTATE_COUNT = 0 DT_FOREACH_CHILD_STATUS_OKAY(PSTATE_ROOT, + CPU_FREQ_COUNT_OKAY_CHILD) }; + +BUILD_ASSERT(DT_NODE_EXISTS(PSTATE_ROOT), + "cpu_freq: performance_states node missing in devicetree"); +BUILD_ASSERT(CPU_FREQ_PSTATE_COUNT > 0, + "cpu_freq: No P-states defined in devicetree"); + #if defined(CONFIG_SMP) && (CONFIG_MP_MAX_NUM_CPUS > 1) static struct k_ipi_work cpu_freq_work;