[PATCH 5/7] console: implement console_putc in terms of console_putbin

Ahmad Fatoum a.fatoum at barebox.org
Mon Apr 13 03:09:40 PDT 2026


console_putc() and console_putbin() both have logic to handle different
stages of console initialization.

Implement the former in terms of the latter to remove the duplication.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 common/console.c | 36 +++++-------------------------------
 1 file changed, 5 insertions(+), 31 deletions(-)

diff --git a/common/console.c b/common/console.c
index 014ce2916835..0ce89390864b 100644
--- a/common/console.c
+++ b/common/console.c
@@ -573,40 +573,14 @@ EXPORT_SYMBOL(tstc);
 
 int console_putc(struct console_device *con, char c)
 {
-	int init = initialized;
 	bool crlf = c == '\n';
-	unsigned int ch;
 
-	ch = console_dev_is_std(con);
-	if (!ch) {
-		if (crlf)
-			con->putc(con, '\r');
-		con->putc(con, c);
-	}
+	if (crlf)
+		console_putbin(con, "\r\n", 2);
+	else
+		console_putbin(con, &c, 1);
 
-	switch (init) {
-	case CONSOLE_UNINITIALIZED:
-		console_init_early();
-		fallthrough;
-	case CONSOLE_INITIALIZED_BUFFER:
-		kfifo_putc(console_output_fifo, c);
-		if (crlf)
-			putc_ll('\r');
-		putc_ll(c);
-		return 1 + crlf;
-
-	case CONSOLE_INIT_FULL:
-		for_each_console(cdev) {
-			if (cdev->f_active & ch)
-				console_putc(cdev, c);
-		}
-		return 1 + crlf;
-	default:
-		/* If we have problems inititalizing our data
-		 * get them early
-		 */
-		hang();
-	}
+	return 1 + crlf;
 }
 EXPORT_SYMBOL(console_putc);
 
-- 
2.47.3




More information about the barebox mailing list