console: add console_flush_stdin()

Add a common helper console_flush_stdin() to drain all pending
characters from stdin. This consolidates the open-coded
while (tstc()) getchar() pattern that appeared in multiple places
across the tree.

Signed-off-by: Gregor Herburger <gregor.herburger@linutronix.de>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Gregor Herburger
2026-04-13 17:24:53 +02:00
committed by Tom Rini
parent 3abc7c1d46
commit 2c8fdd7aea
7 changed files with 26 additions and 23 deletions

View File

@@ -6,6 +6,7 @@
* Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de>
*/
#include <command.h>
#include <console.h>
#include <linux/delay.h>
static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -17,8 +18,7 @@ static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc,
printf("To terminate type 'x'\n");
/* Empty input buffer */
while (tstc())
getchar();
console_flush_stdin();
for (;;) {
int c = getchar();

View File

@@ -6,8 +6,9 @@
*/
#include <ansi.h>
#include <cli.h>
#include <charset.h>
#include <cli.h>
#include <console.h>
#include <efi_device_path.h>
#include <efi_loader.h>
#include <efi_load_initrd.h>
@@ -167,8 +168,7 @@ static void eficonfig_menu_adjust(struct efimenu *efi_menu, bool add)
void eficonfig_print_msg(char *msg)
{
/* Flush input */
while (tstc())
getchar();
console_flush_stdin();
printf(ANSI_CURSOR_HIDE
ANSI_CLEAR_CONSOLE

View File

@@ -7,6 +7,7 @@
#include <ansi.h>
#include <charset.h>
#include <console.h>
#include <hexdump.h>
#include <log.h>
#include <malloc.h>
@@ -288,8 +289,7 @@ static efi_status_t eficonfig_process_show_siglist(void *data)
}
}
while (tstc())
getchar();
console_flush_stdin();
printf("\n\n Press any key to continue");
getchar();