From 29400b18a6fb972a29a75f385cd88c370589b158 Mon Sep 17 00:00:00 2001 From: Wojciech Slenska Date: Fri, 28 Oct 2022 12:10:14 +0200 Subject: [PATCH] shell: shell_log_backend: added check for msg allocation When the message buffer cannot be allocated, dropped package counter should be incremented. Signed-off-by: Wojciech Slenska --- subsys/shell/shell_log_backend.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/subsys/shell/shell_log_backend.c b/subsys/shell/shell_log_backend.c index fae9315554f..94839ff8364 100644 --- a/subsys/shell/shell_log_backend.c +++ b/subsys/shell/shell_log_backend.c @@ -123,7 +123,7 @@ static void dropped(const struct log_backend *const backend, uint32_t cnt) atomic_add(&log_backend->control_block->dropped_cnt, cnt); } -static void copy_to_pbuffer(struct mpsc_pbuf_buffer *mpsc_buffer, +static bool copy_to_pbuffer(struct mpsc_pbuf_buffer *mpsc_buffer, union log_msg_generic *msg, uint32_t timeout) { size_t wlen; @@ -133,7 +133,7 @@ static void copy_to_pbuffer(struct mpsc_pbuf_buffer *mpsc_buffer, dst = mpsc_pbuf_alloc(mpsc_buffer, wlen, K_MSEC(timeout)); if (!dst) { /* No space to store the log */ - return; + return false; } /* First word contains internal mpsc packet flags and when copying @@ -148,6 +148,8 @@ static void copy_to_pbuffer(struct mpsc_pbuf_buffer *mpsc_buffer, memcpy(dst_data, src_data, (wlen - hdr_wlen) * sizeof(uint32_t)); mpsc_pbuf_commit(mpsc_buffer, dst); + + return true; } static void process_log_msg(const struct shell *sh, @@ -233,13 +235,13 @@ static void process(const struct log_backend *const backend, if (IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE)) { process_log_msg(sh, log_output, msg, true, colors); } else { - copy_to_pbuffer(mpsc_buffer, msg, - log_backend->timeout); - - if (IS_ENABLED(CONFIG_MULTITHREADING)) { - signal = - &sh->ctx->signals[SHELL_SIGNAL_LOG_MSG]; - k_poll_signal_raise(signal, 0); + if (copy_to_pbuffer(mpsc_buffer, msg, log_backend->timeout)) { + if (IS_ENABLED(CONFIG_MULTITHREADING)) { + signal = &sh->ctx->signals[SHELL_SIGNAL_LOG_MSG]; + k_poll_signal_raise(signal, 0); + } + } else { + dropped(backend, 1); } }