Skip to content

Commit 137097f

Browse files
cfriedtcarlescufi
authored andcommitted
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 zephyrproject-rtos#15196, added in zephyrproject-rtos#16194, and it would appear that the regression happened in c5f2cde. Signed-off-by: Christopher Friedt <[email protected]>
1 parent 90b9809 commit 137097f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

subsys/logging/log_core.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,11 @@ static struct log_msg *msg_alloc(struct mpsc_pbuf_buffer *buffer, uint32_t wlen)
597597
return NULL;
598598
}
599599

600-
return (struct log_msg *)mpsc_pbuf_alloc(buffer, wlen,
601-
K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS));
600+
return (struct log_msg *)mpsc_pbuf_alloc(
601+
buffer, wlen,
602+
(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS == -1)
603+
? K_FOREVER
604+
: K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS));
602605
}
603606

604607
struct log_msg *z_log_msg_alloc(uint32_t wlen)

0 commit comments

Comments
 (0)