Skip to content

Commit

Permalink
logging: log_core: correct timeout of -1 ms to K_FOREVER
Browse files Browse the repository at this point in the history
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 c5f2cde.

(cherry picked from commit 137097f)

Original-Signed-off-by: Christopher Friedt <cfriedt@meta.com>
GitOrigin-RevId: 137097f
Change-Id: I2ee43e9626e063a7de0a536e05452db337411b73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4942110
Reviewed-by: Keith Short <keithshort@chromium.org>
Tested-by: Keith Short <keithshort@chromium.org>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: Keith Short <keithshort@chromium.org>
  • Loading branch information
cfriedt authored and Chromeos LUCI committed Oct 16, 2023
1 parent c042401 commit 85562ae
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions subsys/logging/log_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,11 @@ static struct log_msg *msg_alloc(struct mpsc_pbuf_buffer *buffer, uint32_t wlen)
return NULL;
}

return (struct log_msg *)mpsc_pbuf_alloc(buffer, wlen,
K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS));
return (struct log_msg *)mpsc_pbuf_alloc(
buffer, wlen,
(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS == -1)
? K_FOREVER
: K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS));
}

struct log_msg *z_log_msg_alloc(uint32_t wlen)
Expand Down

0 comments on commit 85562ae

Please sign in to comment.