diff options
author | Yuval Peress <peress@chromium.org> | 2021-06-29 23:41:50 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-30 19:07:58 +0000 |
commit | 2e40fb4eb9faccc6c4002e8821dc876ea3979f55 (patch) | |
tree | 70c012da11ffa32733dcdb6534f5becfb128d765 /zephyr | |
parent | 3c3f146e86216a03c5946ceedf0996e8c647c55c (diff) | |
download | chrome-ec-2e40fb4eb9faccc6c4002e8821dc876ea3979f55.tar.gz |
zephyr: Fix duplicate ec console
Logs in /var/log/cros_ec.log contained many duplicate entries. This was
caused by not moving the actual head pointer when reading from the
buffer.
BRANCH=none
BUG=b:180423400
TEST=Flash lazor and observe /var/log/cros_ec.log
Signed-off-by: Yuval Peress <peress@chromium.org>
Change-Id: I7951d2fc3e6f13a5d6aebcf0b347238bcb790973
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2995713
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/shim/src/console_buffer.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/zephyr/shim/src/console_buffer.c b/zephyr/shim/src/console_buffer.c index a8f0cc24b8..aa3a2300e6 100644 --- a/zephyr/shim/src/console_buffer.c +++ b/zephyr/shim/src/console_buffer.c @@ -66,44 +66,51 @@ enum ec_status uart_console_read_buffer_init(void) int uart_console_read_buffer(uint8_t type, char *dest, uint16_t dest_size, uint16_t *write_count_out) { - uint32_t head; + uint32_t *head; uint16_t write_count = 0; switch (type) { case CONSOLE_READ_NEXT: /* Start from beginning of latest snapshot */ - head = current_snapshot_idx; + head = ¤t_snapshot_idx; break; case CONSOLE_READ_RECENT: /* Start from end of previous snapshot */ - head = previous_snapshot_idx; + head = &previous_snapshot_idx; break; default: return EC_RES_INVALID_PARAM; } - if (head == tail_idx) - /* No new data, return empty response */ - return EC_RES_SUCCESS; - /* We need to make sure we have room for at least the null byte */ if (dest_size == 0) return EC_RES_INVALID_PARAM; + if (k_mutex_lock(&console_write_lock, K_MSEC(100))) + /* Failed to acquire console buffer mutex */ + return EC_RES_TIMEOUT; + + if (*head == tail_idx) { + /* No new data, return empty response */ + k_mutex_unlock(&console_write_lock); + return EC_RES_SUCCESS; + } + do { if (write_count >= dest_size - 1) /* Buffer is full, minus the space for a null byte */ break; - dest[write_count] = console_buf[head]; + dest[write_count] = console_buf[*head]; write_count++; - head = next_idx(head); - } while (head != tail_idx); + *head = next_idx(*head); + } while (*head != tail_idx); dest[write_count] = '\0'; write_count++; *write_count_out = write_count; + k_mutex_unlock(&console_write_lock); return EC_RES_SUCCESS; } |