From a49845f198af088c4e5e0019edbf519344d78c97 Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Tue, 4 Dec 2018 15:29:14 +0000 Subject: [PATCH] usb kbd fixes Signed-off-by: Peter Robinson --- common/usb_kbd.c | 66 +++++++++++++++++++++++++++++++++++------------ include/console.h | 2 -- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 020f0d4117f..47674ce4458 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -518,25 +518,59 @@ static int probe_usb_keyboard(struct usb_device *dev) return error; stdinname = env_get("stdin"); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - error = iomux_doenv(stdin, stdinname); - if (error) - return error; -#else - /* Check if this is the standard input device. */ - if (strcmp(stdinname, DEVNAME)) - return 1; + if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { + char *devname = DEVNAME; + char *newstdin = NULL; + /* + * stdin might not be set yet.. either way, with console- + * mux the sensible thing to do is add ourselves to the + * list of stdio devices: + */ + if (stdinname && !strstr(stdinname, DEVNAME)) { + newstdin = malloc(strlen(stdinname) + + strlen(","DEVNAME) + 1); + sprintf(newstdin, "%s,"DEVNAME, stdinname); + stdinname = newstdin; + } else if (!stdinname) { + stdinname = devname; + } + error = iomux_doenv(stdin, stdinname); + free(newstdin); + if (error) + goto unregister_stdio; + } else { + /* Check if this is the standard input device. */ + if (strcmp(stdinname, DEVNAME)) { + error = -1; + goto unregister_stdio; + } - /* Reassign the console */ - if (overwrite_console()) - return 1; + /* Reassign the console */ + if (overwrite_console()) { + error = -1; + goto unregister_stdio; + } - error = console_assign(stdin, DEVNAME); - if (error) - return error; -#endif + error = console_assign(stdin, DEVNAME); + if (error) + goto unregister_stdio; + } + + return 0; +unregister_stdio: + /* + * If probe fails, the device will be removed.. leaving dangling + * pointers if the stdio device is not unregistered. If u-boot + * is built without stdio_deregister(), just pretend to succeed + * in order to avoid dangling pointers. + */ +#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) + stdio_deregister(DEVNAME, 1); + return error; +#else return 0; +#endif } #if !CONFIG_IS_ENABLED(DM_USB) @@ -642,7 +676,7 @@ static int usb_kbd_remove(struct udevice *dev) return 0; err: - printf("%s: warning, ret=%d", __func__, ret); + printf("%s: warning, ret=%d\n", __func__, ret); return ret; } diff --git a/include/console.h b/include/console.h index e935c601f12..6382ec8e0d6 100644 --- a/include/console.h +++ b/include/console.h @@ -56,8 +56,6 @@ int console_announce_r(void); /* * CONSOLE multiplexing. */ -#ifdef CONFIG_CONSOLE_MUX #include -#endif #endif -- 2.19.2