[U-Boot] [PATCH 6/6] stdio: dm: Optimize stdio_print_current_devices()

Marek Vasut marex at denx.de
Sat Sep 1 00:44:15 CEST 2012


Rework the function to be more compact. This results in a minor
code size reduction.

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
---
 common/console.c |   39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/common/console.c b/common/console.c
index 22516a5..9558abe 100644
--- a/common/console.c
+++ b/common/console.c
@@ -604,28 +604,27 @@ int console_init_f(void)
 void stdio_print_current_devices(void)
 {
 #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
+	int i;
 	struct stdio_dev *sio;
+	const struct {
+		const int fd;
+		const char * const name;
+		const char * const type;
+	} sp[MAX_FILES] = {
+		{ stdin,  "In:    ", "input", },
+		{ stdout, "Out:   ", "output", },
+		{ stderr, "Err:   ", "error", },
+	};
+
 	/* Print information */
-	puts("In:    ");
-	sio = stdio_get_fd(stdin);
-	if (sio == NULL)
-		puts("No input devices available!\n");
-	else
-		printf("%s\n", sio->name);
-
-	puts("Out:   ");
-	sio = stdio_get_fd(stdout);
-	if (sio == NULL)
-		puts("No output devices available!\n");
-	else
-		printf("%s\n", sio->name);
-
-	puts("Err:   ");
-	sio = stdio_get_fd(stderr);
-	if (sio == NULL)
-		puts("No error devices available!\n");
-	else
-		printf("%s\n", sio->name);
+	for (i = 0; i < MAX_FILES; i++) {
+		sio = stdio_get_fd(sp[i].fd);
+		if (sio)
+			printf("%s%s\n", sp[i].name, sio->name);
+		else
+			printf("%sNo %s devices available!\n",
+				sp[i].name, sp[i].type);
+	}
 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
 }
 
-- 
1.7.10.4



More information about the U-Boot mailing list