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 <wsl@trackunit.com>
This commit is contained in:
Wojciech Slenska 2022-10-28 12:10:14 +02:00 committed by Carles Cufí
commit 29400b18a6

View file

@ -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);
}
}