Skip to contentSkip to conversation

usb: kbd: don't fail with iomux

PATCH New Rob Clark 3 participants 4 messages Aug 3, 2017 – Aug 4, 2017

lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 usb: kbd: don't fail with iomux

stdin might not be set, which would cause iomux_doenv() to fail therefore causing probe_usb_keyboard() to fail. Furthermore if we do have iomux enabled, the sensible thing (in terms of user experience) would be to simply add ourselves to the list of stdin devices.

This fixes an issue with usbkbd on dragonboard410c with distro- bootcmd, where stdin is not set (so stdinname is null).

---
 common/usb_kbd.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
common/usb_kbd.c +15 -0
index d2d29cc98f..703dd748f5 100644
@@ -517,7 +517,22 @@ static int probe_usb_keyboard(struct usb_device *dev)
 
 	stdinname = getenv("stdin");
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
+	char *devname = DEVNAME;
+	/*
+	 * 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)) {
+		char *newstdin = malloc(strlen(stdinname) + strlen(","DEVNAME) + 1);
+		sprintf(newstdin, "%s,"DEVNAME, stdinname);
+		stdinname = newstdin;
+	} else if (!stdinname) {
+		stdinname = devname;
+	}
 	error = iomux_doenv(stdin, stdinname);
+	if (stdinname != devname)
+		free(stdinname);
 	if (error)
 		return error;
 #else
Signature · 1 line
2.13.0
#1 lore raw

PATCH 1/1 usb: kbd: don't fail with iomux

Hi Rob,

Quoted 7 lines · Rob Clark

stdin might not be set, which would cause iomux_doenv() to fail therefore causing probe_usb_keyboard() to fail. Furthermore if we do have iomux enabled, the sensible thing (in terms of user experience) would be to simply add ourselves to the list of stdin devices.

This fixes an issue with usbkbd on dragonboard410c with distro- bootcmd, where stdin is not set (so stdinname is null).

Is this version 2?

Quoted 20 lines
---
 common/usb_kbd.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
common/usb_kbd.c +6 -0
index d2d29cc98f..703dd748f5 100644
@@ -517,7 +517,22 @@ static int probe_usb_keyboard(struct usb_device *dev)
 
        stdinname = getenv("stdin");
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
+       char *devname = DEVNAME;
+       /*
+        * 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:
+        */

common/usb_kbd.c static int probe_usb_keyboard(struct usb_device *dev) · line 535

Quoted 10 lines
common/usb_kbd.c +9 -0
+       if (stdinname && !strstr(stdinname, DEVNAME)) {
+               char *newstdin = malloc(strlen(stdinname) + strlen(","DEVNAME) + 1);
+               sprintf(newstdin, "%s,"DEVNAME, stdinname);
+               stdinname = newstdin;
+       } else if (!stdinname) {
+               stdinname = devname;
+       }
        error = iomux_doenv(stdin, stdinname);
+       if (stdinname != devname)
+               free(stdinname);

Are you sure that free() will work? It looks like it is intended to free newstdin. I think it would be better to have a boolean for whether to free(), instead.

Quoted 6 lines
common/usb_kbd.c +0 -1
        if (error)
                return error;
 #else
--

2.13.0

Regards,
Simon

author
#2 lore raw

PATCH 1/1 usb: kbd: don't fail with iomux

Quoted 8 lines · Simon Glass

Hi Rob,

Quoted 5 lines · Rob Clark

stdin might not be set, which would cause iomux_doenv() to fail therefore causing probe_usb_keyboard() to fail. Furthermore if we do have iomux enabled, the sensible thing (in terms of user experience) would be to simply add ourselves to the list of stdin devices.

Quoted 4 lines
Quoted 2 lines

This fixes an issue with usbkbd on dragonboard410c with distro- bootcmd, where stdin is not set (so stdinname is null).

Is this version 2?

yes, this is the actual v2 (note the fake v2 I sent earlier today)

Quoted 26 lines
Quoted 26 lines
---
 common/usb_kbd.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
common/usb_kbd.c +12 -0
index d2d29cc98f..703dd748f5 100644
@@ -517,7 +517,22 @@ static int probe_usb_keyboard(struct usb_device *dev)
 
        stdinname = getenv("stdin");
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
+       char *devname = DEVNAME;
+       /*
+        * 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)) {
+               char *newstdin = malloc(strlen(stdinname) + strlen(","DEVNAME) + 1);
+               sprintf(newstdin, "%s,"DEVNAME, stdinname);
+               stdinname = newstdin;
+       } else if (!stdinname) {
+               stdinname = devname;
Quoted 8 lines

common/usb_kbd.c static int probe_usb_keyboard(struct usb_device *dev) · line 535

Quoted 4 lines
common/usb_kbd.c +3 -0
+       }
        error = iomux_doenv(stdin, stdinname);
+       if (stdinname != devname)
+               free(stdinname);

Are you sure that free() will work? It looks like it is intended to free newstdin. I think it would be better to have a boolean for whether to free(), instead.

oh, that's true.. on v1 you would always go down one or the other leg of the if/else, which is no longer the case

BR,
-R

Quoted 9 lines
Quoted 6 lines
common/usb_kbd.c +0 -1
        if (error)
                return error;
 #else
--

2.13.0

Regards,
Simon

#3 lore raw

PATCH 1/1 usb: kbd: don't fail with iomux

In reply to Rob Clark
Quoted 5 lines · Rob Clark

stdin might not be set, which would cause iomux_doenv() to fail therefore causing probe_usb_keyboard() to fail. Furthermore if we do have iomux enabled, the sensible thing (in terms of user experience) would be to simply add ourselves to the list of stdin devices.

Quoted 8 lines

This fixes an issue with usbkbd on dragonboard410c with distro- bootcmd, where stdin is not set (so stdinname is null).

---
 common/usb_kbd.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)