From f7a95f64b285ce108642c52cc18bc49aa03e28ea Mon Sep 17 00:00:00 2001 From: Dong Wang Date: Fri, 14 Mar 2025 13:35:10 +0800 Subject: [PATCH] logging: Assign IDs to log backends early during log_core_init This commit moves the assignment of backend IDs from the 'z_log_init' function to the earlier 'log_core_init' function. This ensures that backend IDs are assigned before they are used in the 'log_backend_enable' function, preventing incorrect settings of log dynamic filters. Signed-off-by: Dong Wang (cherry picked from commit 3fac83151db3ea6f8765c8f6514674f4ce939cd2) --- subsys/logging/log_core.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index 81bd3243e3fb9..3273c03e3722a 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -286,6 +286,14 @@ void log_core_init(void) if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) { z_log_runtime_filters_init(); } + + STRUCT_SECTION_FOREACH(log_backend, backend) { + uint32_t id; + /* As first slot in filtering mask is reserved, backend ID has offset.*/ + id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX; + id += backend - log_backend_get(0); + log_backend_id_set(backend, id); + } } static uint32_t activate_foreach_backend(uint32_t mask) @@ -329,12 +337,6 @@ static uint32_t z_log_init(bool blocking, bool can_sleep) int backend_index = 0; STRUCT_SECTION_FOREACH(log_backend, backend) { - uint32_t id; - /* As first slot in filtering mask is reserved, backend ID has offset.*/ - id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX; - id += backend - log_backend_get(0); - log_backend_id_set(backend, id); - /* Activate autostart backends */ if (backend->autostart) { log_backend_init(backend);