From: Marek Vasut Date: Sat, 1 Sep 2012 00:44:15 +0200 Subject: [U-Boot] [PATCH 6/6] stdio: dm: Optimize stdio_print_current_devices() In-Reply-To: <1346453055-30888-1-git-send-email-marex@denx.de> References: <1346453055-30888-1-git-send-email-marex@denx.de> Message-ID: <1346453055-30888-7-git-send-email-marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Rework the function to be more compact. This results in a minor code size reduction. Signed-off-by: Marek Vasut Cc: Wolfgang Denk --- 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