diff options
author | Simon Glass <sjg@chromium.org> | 2021-05-08 15:59:56 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-06-08 18:39:09 +0300 |
commit | c1a2bb4f836a1c96c8e39a67be9795d462ec3356 (patch) | |
tree | df63c2604df3c23de4872d0b849b10f8c76afdd6 /common | |
parent | 24e1e8841c59956aaf0bd65720d0dbdd61aa3632 (diff) | |
download | u-boot-c1a2bb4f836a1c96c8e39a67be9795d462ec3356.tar.xz |
console: Report an error when output buffer is exhausted
If the console output buffer is exhausted, characters are silently dropped
from the end. Detect this condition and report an error when reading back
the characters.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/console.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/common/console.c b/common/console.c index 561cdf36a7..73edb28799 100644 --- a/common/console.c +++ b/common/console.c @@ -95,16 +95,22 @@ static void console_record_putc(const char c) { if (!(gd->flags & GD_FLG_RECORD)) return; - if (gd->console_out.start) - membuff_putbyte((struct membuff *)&gd->console_out, c); + if (gd->console_out.start && + !membuff_putbyte((struct membuff *)&gd->console_out, c)) + gd->flags |= GD_FLG_RECORD_OVF; } static void console_record_puts(const char *s) { if (!(gd->flags & GD_FLG_RECORD)) return; - if (gd->console_out.start) - membuff_put((struct membuff *)&gd->console_out, s, strlen(s)); + if (gd->console_out.start) { + int len = strlen(s); + + if (membuff_put((struct membuff *)&gd->console_out, s, len) != + len) + gd->flags |= GD_FLG_RECORD_OVF; + } } static int console_record_getc(void) @@ -742,6 +748,7 @@ void console_record_reset(void) { membuff_purge((struct membuff *)&gd->console_out); membuff_purge((struct membuff *)&gd->console_in); + gd->flags &= ~GD_FLG_RECORD_OVF; } int console_record_reset_enable(void) @@ -754,6 +761,9 @@ int console_record_reset_enable(void) int console_record_readline(char *str, int maxlen) { + if (gd->flags & GD_FLG_RECORD_OVF) + return -ENOSPC; + return membuff_readline((struct membuff *)&gd->console_out, str, maxlen, ' '); } |