{"id":2222761,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2222761/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20260413152526.153605-1-gregor.herburger@linutronix.de/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.2/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260413152526.153605-1-gregor.herburger@linutronix.de>","list_archive_url":null,"date":"2026-04-13T15:24:53","name":"[v4,1/2] console: add console_flush_stdin()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"0e3c765c0e3a39f3ec2c45641affe445f2b66d8f","submitter":{"id":93018,"url":"http://patchwork.ozlabs.org/api/1.2/people/93018/?format=json","name":"Gregor Herburger","email":"gregor.herburger@linutronix.de"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/1.2/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20260413152526.153605-1-gregor.herburger@linutronix.de/mbox/","series":[{"id":499722,"url":"http://patchwork.ozlabs.org/api/1.2/series/499722/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=499722","date":"2026-04-13T15:24:53","name":"[v4,1/2] console: add console_flush_stdin()","version":4,"mbox":"http://patchwork.ozlabs.org/series/499722/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2222761/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2222761/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256\n header.s=2020 header.b=wRJ09C4g;\n\tdkim=pass header.d=linutronix.de header.i=@linutronix.de\n header.a=ed25519-sha256 header.s=2020e header.b=w0d0zLbh;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=linutronix.de","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (2048-bit key;\n secure) header.d=linutronix.de header.i=@linutronix.de header.b=\"wRJ09C4g\";\n\tdkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de\n header.b=\"w0d0zLbh\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=linutronix.de","phobos.denx.de;\n spf=pass smtp.mailfrom=gregor.herburger@linutronix.de"],"Received":["from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvWSs40PWz1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 01:25:49 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 8080C839D5;\n\tMon, 13 Apr 2026 17:25:46 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id 534ED839DF; Mon, 13 Apr 2026 17:25:45 +0200 (CEST)","from galois.linutronix.de (Galois.linutronix.de [193.142.43.55])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 45FCB836AC\n for <u-boot@lists.denx.de>; Mon, 13 Apr 2026 17:25:43 +0200 (CEST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,\n RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED,\n SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2","From":"Gregor Herburger <gregor.herburger@linutronix.de>","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de;\n s=2020; t=1776093942;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding;\n bh=T5ooMbjkuDrMMtqKvLQ/8OHW6Ray8ASSxTPx7qJxYXo=;\n b=wRJ09C4gAQ4UjxJffeEvoL2pJBu8oBHYsz1f+Q0nZuPNUc7nOlGWrIxIr9pP+yLMj1mynA\n J1gEdPpMQnwgoIjrOCIcWxhZHJQXtFHIrZRoNPTajhVqsdCJr0/zzO0OYHEt1+S6tgjvPo\n twJl1FcvXRgjsMmU/coi3j76ovWVva/jNrSUaJM7dc0eo1jOjLfdf02VaOmT1Z7goTEFV0\n ai6jgVaO4itoyNEwnU7TtkwIeXFuzNFJWaFUNEUnWQak2Ame6aCLI0L7T6ToNQrpnLKLea\n g316eDSKrRMl6m70qrDAbfwDvEIYkGQoX31maQaDPCVpuVGMEVMhf0Pgla2UoQ==","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;\n s=2020e; t=1776093942;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding;\n bh=T5ooMbjkuDrMMtqKvLQ/8OHW6Ray8ASSxTPx7qJxYXo=;\n b=w0d0zLbhNQgTZftIGEAm8C+Hm1JWhbSjEEvARh5fLkSwdl3llAEFfqeucVhMxXBU5qA072\n rGgD+iYUN4u81qBQ=="],"To":"u-boot@lists.denx.de,\n\tQuentin Schulz <quentin.schulz@cherry.de>","Cc":"Gregor Herburger <gregor.herburger@linutronix.de>,\n Alexander Sverdlin <alexander.sverdlin@siemens.com>,\n Simon Glass <sjg@chromium.org>, Casey Connolly <casey.connolly@linaro.org>,\n David Zang <davidzangcs@gmail.com>,\n Heinrich Schuchardt <xypron.glpk@gmx.de>,\n Ilias Apalodimas <ilias.apalodimas@linaro.org>,\n Marek Vasut <marek.vasut+renesas@mailbox.org>,\n Sam Protsenko <semen.protsenko@linaro.org>,\n Sughosh Ganu <sughosh.ganu@arm.com>, Tom Rini <trini@konsulko.com>","Subject":"[PATCH v4 1/2] console: add console_flush_stdin()","Date":"Mon, 13 Apr 2026 17:24:53 +0200","Message-ID":"<20260413152526.153605-1-gregor.herburger@linutronix.de>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Add a common helper console_flush_stdin() to drain all pending\ncharacters from stdin. This consolidates the open-coded\nwhile (tstc()) getchar() pattern that appeared in multiple places\nacross the tree.\n\nSigned-off-by: Gregor Herburger <gregor.herburger@linutronix.de>\nReviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>\nReviewed-by: Quentin Schulz <quentin.schulz@cherry.de>\nReviewed-by: Simon Glass <sjg@chromium.org>\n\n---\n\n(no changes since v2)\n\nChanges in v2:\n- New\n- New\n\n cmd/conitrace.c              |  4 ++--\n cmd/eficonfig.c              |  6 +++---\n cmd/eficonfig_sbkey.c        |  4 ++--\n common/autoboot.c            | 11 +----------\n common/console.c             | 12 ++++++++++--\n include/console.h            |  5 +++++\n lib/efi_loader/efi_console.c |  7 +++----\n 7 files changed, 26 insertions(+), 23 deletions(-)","diff":"diff --git a/cmd/conitrace.c b/cmd/conitrace.c\nindex 6cc113328eb..aef094e03df 100644\n--- a/cmd/conitrace.c\n+++ b/cmd/conitrace.c\n@@ -6,6 +6,7 @@\n  * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de>\n  */\n #include <command.h>\n+#include <console.h>\n #include <linux/delay.h>\n \n static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc,\n@@ -17,8 +18,7 @@ static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc,\n \tprintf(\"To terminate type 'x'\\n\");\n \n \t/* Empty input buffer */\n-\twhile (tstc())\n-\t\tgetchar();\n+\tconsole_flush_stdin();\n \n \tfor (;;) {\n \t\tint c = getchar();\ndiff --git a/cmd/eficonfig.c b/cmd/eficonfig.c\nindex d8d946c87ac..60c39bc3a99 100644\n--- a/cmd/eficonfig.c\n+++ b/cmd/eficonfig.c\n@@ -6,8 +6,9 @@\n  */\n \n #include <ansi.h>\n-#include <cli.h>\n #include <charset.h>\n+#include <cli.h>\n+#include <console.h>\n #include <efi_device_path.h>\n #include <efi_loader.h>\n #include <efi_load_initrd.h>\n@@ -167,8 +168,7 @@ static void eficonfig_menu_adjust(struct efimenu *efi_menu, bool add)\n void eficonfig_print_msg(char *msg)\n {\n \t/* Flush input */\n-\twhile (tstc())\n-\t\tgetchar();\n+\tconsole_flush_stdin();\n \n \tprintf(ANSI_CURSOR_HIDE\n \t       ANSI_CLEAR_CONSOLE\ndiff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c\nindex b3325a540f9..a6c5416d3a5 100644\n--- a/cmd/eficonfig_sbkey.c\n+++ b/cmd/eficonfig_sbkey.c\n@@ -7,6 +7,7 @@\n \n #include <ansi.h>\n #include <charset.h>\n+#include <console.h>\n #include <hexdump.h>\n #include <log.h>\n #include <malloc.h>\n@@ -288,8 +289,7 @@ static efi_status_t eficonfig_process_show_siglist(void *data)\n \t\t}\n \t}\n \n-\twhile (tstc())\n-\t\tgetchar();\n+\tconsole_flush_stdin();\n \n \tprintf(\"\\n\\n  Press any key to continue\");\n \tgetchar();\ndiff --git a/common/autoboot.c b/common/autoboot.c\nindex 1783ef92c94..4b80ddb5b28 100644\n--- a/common/autoboot.c\n+++ b/common/autoboot.c\n@@ -315,15 +315,6 @@ static int passwd_abort_key(uint64_t etime)\n \treturn abort;\n }\n \n-/**\n- * flush_stdin() - drops all pending characters from stdin\n- */\n-static void flush_stdin(void)\n-{\n-\twhile (tstc())\n-\t\t(void)getchar();\n-}\n-\n /**\n  * fallback_to_sha256() - check whether we should fall back to sha256\n  *                        password checking\n@@ -354,7 +345,7 @@ static int abortboot_key_sequence(int bootdelay)\n \tuint64_t etime = endtick(bootdelay);\n \n \tif (IS_ENABLED(CONFIG_AUTOBOOT_FLUSH_STDIN))\n-\t\tflush_stdin();\n+\t\tconsole_flush_stdin();\n #  ifdef CONFIG_AUTOBOOT_PROMPT\n \t/*\n \t * CONFIG_AUTOBOOT_PROMPT includes the %d for all boards.\ndiff --git a/common/console.c b/common/console.c\nindex 22e554cf203..54d1249422d 100644\n--- a/common/console.c\n+++ b/common/console.c\n@@ -643,6 +643,15 @@ int tstc(void)\n \treturn serial_tstc();\n }\n \n+/**\n+ * console_flush_stdin() - drops all pending characters from stdin\n+ */\n+void console_flush_stdin(void)\n+{\n+\twhile (tstc())\n+\t\t(void)getchar();\n+}\n+\n #define PRE_CONSOLE_FLUSHPOINT1_SERIAL\t\t\t0\n #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL\t1\n \n@@ -914,8 +923,7 @@ int confirm_yesno(void)\n \tchar str_input[5];\n \n \t/* Flush input */\n-\twhile (tstc())\n-\t\tgetchar();\n+\tconsole_flush_stdin();\n \ti = 0;\n \twhile (i < sizeof(str_input)) {\n \t\tstr_input[i] = getchar();\ndiff --git a/include/console.h b/include/console.h\nindex 8d0d7bb8a4c..01a04f28f31 100644\n--- a/include/console.h\n+++ b/include/console.h\n@@ -202,6 +202,11 @@ int console_clear(void);\n  */\n int console_remove_by_name(const char *name);\n \n+/**\n+ * console_flush_stdin() - drops all pending characters from stdin\n+ */\n+void console_flush_stdin(void);\n+\n /*\n  * CONSOLE multiplexing.\n  */\ndiff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c\nindex 068d1a0a7b7..f83415f2ed3 100644\n--- a/lib/efi_loader/efi_console.c\n+++ b/lib/efi_loader/efi_console.c\n@@ -9,6 +9,7 @@\n \n #include <ansi.h>\n #include <charset.h>\n+#include <console.h>\n #include <efi_device_path.h>\n #include <malloc.h>\n #include <time.h>\n@@ -299,8 +300,7 @@ static int query_console_serial(int *rows, int *cols)\n \tint n[2];\n \n \t/* Empty input buffer */\n-\twhile (tstc())\n-\t\tgetchar();\n+\tconsole_flush_stdin();\n \n \t/*\n \t * Not all terminals understand CSI [18t for querying the console size.\n@@ -957,8 +957,7 @@ static void efi_cin_check(void)\n  */\n static void efi_cin_empty_buffer(void)\n {\n-\twhile (tstc())\n-\t\tgetchar();\n+\tconsole_flush_stdin();\n \tkey_available = false;\n }\n \n","prefixes":["v4","1/2"]}