aboutsummaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorSimon Glass2021-05-08 06:59:56 -0600
committerTom Rini2021-06-08 11:39:09 -0400
commitc1a2bb4f836a1c96c8e39a67be9795d462ec3356 (patch)
treedf63c2604df3c23de4872d0b849b10f8c76afdd6 /common/console.c
parent24e1e8841c59956aaf0bd65720d0dbdd61aa3632 (diff)
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/console.c')
-rw-r--r--common/console.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/common/console.c b/common/console.c
index 561cdf36a74..73edb287992 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, ' ');
}