diff mbox series

[v2] common: console: Fix print complete stdio device list

Message ID 20240117123714.50380-1-patrice.chotard@foss.st.com
State Accepted
Commit 9152a51e3c3af8cd766dfaad50aa5bb97678378c
Delegated to: Tom Rini
Headers show
Series [v2] common: console: Fix print complete stdio device list | expand

Commit Message

Patrice CHOTARD Jan. 17, 2024, 12:37 p.m. UTC
In case CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are on and
stdin or stdout or stderr are missing in environment, as fallback, get
these either from stdio_devices[std] or stdio_devices[std]->name.

Fixes: 6b343ab38d ("console: Print out complete stdio device list")

Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>

---

Changes in v2:
  - simplify code suggested by Bin Meng

 common/console.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

Comments

Bin Meng Jan. 17, 2024, 12:39 p.m. UTC | #1
On Wed, Jan 17, 2024 at 8:37 PM Patrice Chotard
<patrice.chotard@foss.st.com> wrote:
>
> In case CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are on and
> stdin or stdout or stderr are missing in environment, as fallback, get
> these either from stdio_devices[std] or stdio_devices[std]->name.
>
> Fixes: 6b343ab38d ("console: Print out complete stdio device list")
>
> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
>
> ---
>
> Changes in v2:
>   - simplify code suggested by Bin Meng
>
>  common/console.c | 27 ++++++++++++---------------
>  1 file changed, 12 insertions(+), 15 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Marek Vasut Jan. 17, 2024, 1:30 p.m. UTC | #2
On 1/17/24 13:37, Patrice Chotard wrote:
> In case CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are on and
> stdin or stdout or stderr are missing in environment, as fallback, get
> these either from stdio_devices[std] or stdio_devices[std]->name.
> 
> Fixes: 6b343ab38d ("console: Print out complete stdio device list")
> 
> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>

Yes, please, this is a good idea:

Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Tom Rini Jan. 25, 2024, 4:14 p.m. UTC | #3
On Wed, Jan 17, 2024 at 01:37:13PM +0100, Patrice Chotard wrote:

> In case CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are on and
> stdin or stdout or stderr are missing in environment, as fallback, get
> these either from stdio_devices[std] or stdio_devices[std]->name.
> 
> Fixes: 6b343ab38d ("console: Print out complete stdio device list")
> 
> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/console.c b/common/console.c
index cad65891fc9..aa3053bc441 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1049,9 +1049,16 @@  int console_clear(void)
 	return 0;
 }
 
+static char *get_stdio(const u8 std)
+{
+	return stdio_devices[std] ? stdio_devices[std]->name : "No devices available!";
+}
+
 static void stdio_print_current_devices(void)
 {
-	char *stdinname, *stdoutname, *stderrname;
+	char *stdinname = NULL;
+	char *stdoutname = NULL;
+	char *stderrname = NULL;
 
 	if (CONFIG_IS_ENABLED(CONSOLE_MUX) &&
 	    CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)) {
@@ -1059,22 +1066,12 @@  static void stdio_print_current_devices(void)
 		stdinname  = env_get("stdin");
 		stdoutname = env_get("stdout");
 		stderrname = env_get("stderr");
-
-		stdinname = stdinname ? : "No input devices available!";
-		stdoutname = stdoutname ? : "No output devices available!";
-		stderrname = stderrname ? : "No error devices available!";
-	} else {
-		stdinname = stdio_devices[stdin] ?
-			stdio_devices[stdin]->name :
-			"No input devices available!";
-		stdoutname = stdio_devices[stdout] ?
-			stdio_devices[stdout]->name :
-			"No output devices available!";
-		stderrname = stdio_devices[stderr] ?
-			stdio_devices[stderr]->name :
-			"No error devices available!";
 	}
 
+	stdinname = stdinname ? : get_stdio(stdin);
+	stdoutname = stdoutname ? : get_stdio(stdout);
+	stderrname = stderrname ? : get_stdio(stderr);
+
 	/* Print information */
 	puts("In:    ");
 	printf("%s\n", stdinname);