From 79a879e90391cb770cafd9c4723278b245bcf477 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Sun, 15 Oct 2023 09:42:09 -0400 Subject: [PATCH] logging: log_core: correct timeout of -1 ms to K_FOREVER Many releases ago, specifying to block indefinitely in the log processing thread would do just that. However, a subtle bug was introduced such that specifying -1 for `CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS` would have the exact opposite effect than what was intended. As per Kconfig, a value of -1 should translate to a timeout of `K_FOREVER`. However, conversion via `K_MSEC(-1)` results in a `k_timeout_t` that is equal to `K_NO_WAIT` rather than the intent which is `K_FOREVER`. Add a dedicated check to to ensure that a value of -1 is correctly interpreted as `K_FOREVER` in `log_core.c`. For reference, the blocking feature was described in #15196, added in #16194, and it would appear that the regression happened in c5f2cdef09. Signed-off-by: Christopher Friedt (cherry picked from commit 137097f5c3153cefb9f585aa7b2d88bf09a384aa) --- subsys/logging/log_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index 4103efd589e21ac..df8ac728d027e5f 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -1190,8 +1190,11 @@ void z_log_msg2_init(void) struct log_msg2 *z_log_msg2_alloc(uint32_t wlen) { - return (struct log_msg2 *)mpsc_pbuf_alloc(&log_buffer, wlen, - K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS)); + return (struct log_msg *)mpsc_pbuf_alloc( + &log_buffer, wlen, + (CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS == -1) + ? K_FOREVER + : K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS)); } void z_log_msg2_commit(struct log_msg2 *msg)