From 37e4af63a9e4bbd54eac914db8ca6e632ab995c1 Mon Sep 17 00:00:00 2001 From: Ryan McClelland Date: Fri, 1 Nov 2024 16:05:05 -0700 Subject: [PATCH] kernel: thread: fix warning of always false K_KERNEL_STACK_RESERVED can be 0 which can give a warning with -Wtype-limits. Only perform the check if ARCH_KERNEL_STACK_RESERVED is set. Also remove the the unncessary sets in arch.h where it's manually set to 0, it defaults to 0 anyways. Signed-off-by: Ryan McClelland --- include/zephyr/arch/x86/thread_stack.h | 1 - include/zephyr/arch/xtensa/thread_stack.h | 1 - kernel/thread.c | 3 ++- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/zephyr/arch/x86/thread_stack.h b/include/zephyr/arch/x86/thread_stack.h index f22bf4d6853..fb5572055da 100644 --- a/include/zephyr/arch/x86/thread_stack.h +++ b/include/zephyr/arch/x86/thread_stack.h @@ -107,7 +107,6 @@ struct z_x86_thread_stack_header { #define ARCH_KERNEL_STACK_RESERVED CONFIG_MMU_PAGE_SIZE #define ARCH_KERNEL_STACK_OBJ_ALIGN CONFIG_MMU_PAGE_SIZE #else -#define ARCH_KERNEL_STACK_RESERVED 0 #define ARCH_KERNEL_STACK_OBJ_ALIGN ARCH_STACK_PTR_ALIGN #endif diff --git a/include/zephyr/arch/xtensa/thread_stack.h b/include/zephyr/arch/xtensa/thread_stack.h index 816eaf3b97c..6155f0dfe0e 100644 --- a/include/zephyr/arch/xtensa/thread_stack.h +++ b/include/zephyr/arch/xtensa/thread_stack.h @@ -68,7 +68,6 @@ struct xtensa_thread_stack_header { ROUND_UP((size), XTENSA_STACK_SIZE_ALIGN) /* kernel stack */ -#define ARCH_KERNEL_STACK_RESERVED 0 #define ARCH_KERNEL_STACK_OBJ_ALIGN ARCH_STACK_PTR_ALIGN #endif /* _ASMLANGUAGE */ diff --git a/kernel/thread.c b/kernel/thread.c index 184343a70de..f77d70ce494 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -400,6 +400,7 @@ static char *setup_thread_stack(struct k_thread *new_thread, stack_buf_start = K_KERNEL_STACK_BUFFER(stack); stack_buf_size = stack_obj_size - K_KERNEL_STACK_RESERVED; +#if defined(ARCH_KERNEL_STACK_RESERVED) /* Zephyr treats stack overflow as an app bug. But * this particular overflow can be seen by static * analysis so needs to be handled somehow. @@ -407,7 +408,7 @@ static char *setup_thread_stack(struct k_thread *new_thread, if (K_KERNEL_STACK_RESERVED > stack_obj_size) { k_panic(); } - +#endif } #ifdef CONFIG_THREAD_STACK_MEM_MAPPED