From dd63f90f83a12789039bc9a60141b8a50e45c74f Mon Sep 17 00:00:00 2001 From: Benedikt Schmidt Date: Tue, 19 Dec 2023 16:42:34 +0100 Subject: [PATCH] shell: modules: do not use k_thread_foreach with shell callbacks Always use k_thread_foreach_unlocked with callbacks which print something out to the shell, as they might call arch_irq_unlock. Fixes #66660. Signed-off-by: Benedikt Schmidt (cherry picked from commit 4c731f27c6da917d7f4abaa10270bb2440423b17) --- subsys/shell/modules/kernel_service.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/subsys/shell/modules/kernel_service.c b/subsys/shell/modules/kernel_service.c index 94940ddbca4c8d..f6f2afe5104d7e 100644 --- a/subsys/shell/modules/kernel_service.c +++ b/subsys/shell/modules/kernel_service.c @@ -141,11 +141,12 @@ static int cmd_kernel_threads(const struct shell *shell, shell_print(shell, "Scheduler: %u since last call", sys_clock_elapsed()); shell_print(shell, "Threads:"); -#ifdef CONFIG_SMP - k_thread_foreach_unlocked(shell_tdata_dump, (void *)shell); -#else - k_thread_foreach(shell_tdata_dump, (void *)shell); -#endif + /* + * Use the unlocked version as the callback itself might call + * arch_irq_unlock. + */ + k_thread_foreach_unlocked(shell_tdata_dump, (void *)sh); + return 0; } @@ -190,11 +191,11 @@ static int cmd_kernel_stacks(const struct shell *shell, ARG_UNUSED(argc); ARG_UNUSED(argv); -#ifdef CONFIG_SMP - k_thread_foreach_unlocked(shell_stack_dump, (void *)shell); -#else - k_thread_foreach(shell_stack_dump, (void *)shell); -#endif + /* + * Use the unlocked version as the callback itself might call + * arch_irq_unlock. + */ + k_thread_foreach_unlocked(shell_stack_dump, (void *)sh); /* Placeholder logic for interrupt stack until we have better * kernel support, including dumping arch-specific exception-related