[Uboot-stm32] [U-BOOT internal][PATCH] common: console: Fix print complete stdio device list
Patrick DELAUNAY
patrick.delaunay at foss.st.com
Tue Jan 16 15:55:01 UTC 2024
-1
On 1/16/24 15:26, 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 at foss.st.com>
> ---
>
> common/console.c | 26 ++++++++++++++------------
> 1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/common/console.c b/common/console.c
> index cad65891fc9..7efd936ccc0 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -1049,9 +1049,17 @@ int console_clear(void)
> return 0;
> }
>
> +static char *get_stdio(char *buf, const u8 std)
> +{
> + snprintf(buf, sizeof(buf), "No %s devices available!", stdio_names[std]);
> +
> + return stdio_devices[std] ? stdio_devices[std]->name : buf;
> +}
> +
> static void stdio_print_current_devices(void)
> {
> char *stdinname, *stdoutname, *stderrname;
> + char buf[32];
=> same buffer used for the 3 sprintf = only the last only win.
Result
In: No stderr devices available!
Out: No stderrdevices available!
Err: No stderr devices available!
PS: no issue if const char is used / buf can be removed
+static char *get_stdio(const u8 std)
+{
+ return stdio_devices[std] ? stdio_devices[std]->name : "No devices available!"
;
+}
+
>
> if (CONFIG_IS_ENABLED(CONSOLE_MUX) &&
> CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)) {
> @@ -1060,19 +1068,13 @@ static void stdio_print_current_devices(void)
> 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!";
> + stdinname = stdinname ? : get_stdio(buf, stdin);
> + stdoutname = stdoutname ? : get_stdio(buf, stdout);
> + stderrname = stderrname ? : get_stdio(buf, stderr);
> } 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 = get_stdio(buf, stdin);
> + stdoutname = get_stdio(buf, stdout);
> + stderrname = get_stdio(buf, stderr);
> }
>
> /* Print information */
Result
In: No devices available!
Out: No devices available!
Err: No devices available!
More information about the Uboot-stm32
mailing list