Skip to contentSkip to conversation

usb: kbd: don't fail with iomux

PATCH Superseded Rob Clark 2 participants 4 messages Aug 7, 2017 – Aug 8, 2017

lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH v4 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).

---
v2: address Bin's review comments
v3: fix fail with free()ing if usbkbd is already in stdin env variable
pointed out by Simon
v4: use if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { ... }

 common/usb_kbd.c  | 46 +++++++++++++++++++++++++++++++---------------
 include/console.h |  2 --
 2 files changed, 31 insertions(+), 17 deletions(-)
common/usb_kbd.c +31 -15
index d2d29cc98f..8edeb6c4f5 100644
@@ -516,23 +516,39 @@ static int probe_usb_keyboard(struct usb_device *dev)
 		return error;
 
 	stdinname = getenv("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)
+			return error;
+	} else {
+		/* Check if this is the standard input device. */
+		if (strcmp(stdinname, DEVNAME))
+			return 1;
 
-	/* Reassign the console */
-	if (overwrite_console())
-		return 1;
+		/* Reassign the console */
+		if (overwrite_console())
+			return 1;
 
-	error = console_assign(stdin, DEVNAME);
-	if (error)
-		return error;
-#endif
+		error = console_assign(stdin, DEVNAME);
+		if (error)
+			return error;
+	}
 
 	return 0;
 }
include/console.h +0 -2
index cea29ed6dc..7dfd36d7d1 100644
@@ -57,8 +57,6 @@ int console_announce_r(void);
 /*
  * CONSOLE multiplexing.
  */
-#ifdef CONFIG_CONSOLE_MUX
 #include <iomux.h>
-#endif
 
 #endif
Signature · 1 line
2.13.0
#1 lore raw

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

Hi Rob,

Quoted 43 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).

---
v2: address Bin's review comments
v3: fix fail with free()ing if usbkbd is already in stdin env variable
pointed out by Simon
v4: use if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { ... }

 common/usb_kbd.c  | 46 +++++++++++++++++++++++++++++++---------------
 include/console.h |  2 --
 2 files changed, 31 insertions(+), 17 deletions(-)
common/usb_kbd.c +8 -8
index d2d29cc98f..8edeb6c4f5 100644
@@ -516,23 +516,39 @@ static int probe_usb_keyboard(struct usb_device *dev)
                return error;
 
        stdinname = getenv("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:
+                */

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

Quoted 10 lines
common/usb_kbd.c +10 -0
+               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);

Sorry I should have asked this before: isn't free(devname) OK? In previous version, it has a test logic to see whether free is needed.

Quoted 30 lines
common/usb_kbd.c +13 -7
+               if (error)
+                       return error;
+       } else {
+               /* Check if this is the standard input device. */
+               if (strcmp(stdinname, DEVNAME))
+                       return 1;
 
-       /* Reassign the console */
-       if (overwrite_console())
-               return 1;
+               /* Reassign the console */
+               if (overwrite_console())
+                       return 1;
 
-       error = console_assign(stdin, DEVNAME);
-       if (error)
-               return error;
-#endif
+               error = console_assign(stdin, DEVNAME);
+               if (error)
+                       return error;
+       }
 
        return 0;
 }
include/console.h +0 -0
index cea29ed6dc..7dfd36d7d1 100644

include/console.h int console_announce_r(void);

Quoted 9 lines
include/console.h +0 -3
@@ -57,8 +57,6 @@ int console_announce_r(void);
 /*
  * CONSOLE multiplexing.
  */
-#ifdef CONFIG_CONSOLE_MUX
 #include <iomux.h>
-#endif
 
 #endif
--

Regards,
Bin

author
#2 lore raw

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

Quoted 51 lines · Bin Meng

Hi Rob,

Quoted 48 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).

---
v2: address Bin's review comments
v3: fix fail with free()ing if usbkbd is already in stdin env variable
pointed out by Simon
v4: use if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { ... }

 common/usb_kbd.c  | 46 +++++++++++++++++++++++++++++++---------------
 include/console.h |  2 --
 2 files changed, 31 insertions(+), 17 deletions(-)
common/usb_kbd.c +13 -8
index d2d29cc98f..8edeb6c4f5 100644
@@ -516,23 +516,39 @@ static int probe_usb_keyboard(struct usb_device *dev)
                return error;
 
        stdinname = getenv("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;
Quoted 8 lines

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

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

Sorry I should have asked this before: isn't free(devname) OK? In previous version, it has a test logic to see whether free is needed.

it was in the first version of my patch, until I added the &&!strstr() bit to avoid adding usbkbd a second time to stdin if stdin already contained usbkbd. Now we have a case where stdinname is the ptr returned from getenv() which we probably don't want to free() ;-)

BR,
-R

Quoted 42 lines
Quoted 30 lines
common/usb_kbd.c +13 -7
+               if (error)
+                       return error;
+       } else {
+               /* Check if this is the standard input device. */
+               if (strcmp(stdinname, DEVNAME))
+                       return 1;
 
-       /* Reassign the console */
-       if (overwrite_console())
-               return 1;
+               /* Reassign the console */
+               if (overwrite_console())
+                       return 1;
 
-       error = console_assign(stdin, DEVNAME);
-       if (error)
-               return error;
-#endif
+               error = console_assign(stdin, DEVNAME);
+               if (error)
+                       return error;
+       }
 
        return 0;
 }
include/console.h +0 -0
index cea29ed6dc..7dfd36d7d1 100644

include/console.h int console_announce_r(void);

Quoted 9 lines
include/console.h +0 -3
@@ -57,8 +57,6 @@ int console_announce_r(void);
 /*
  * CONSOLE multiplexing.
  */
-#ifdef CONFIG_CONSOLE_MUX
 #include <iomux.h>
-#endif
 
 #endif
--

Regards,
Bin

#3 lore raw

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

Hi Rob,

Quoted 61 lines · Rob Clark
Quoted 51 lines · Bin Meng

Hi Rob,

Quoted 48 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).

---
v2: address Bin's review comments
v3: fix fail with free()ing if usbkbd is already in stdin env variable
pointed out by Simon
v4: use if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { ... }

 common/usb_kbd.c  | 46 +++++++++++++++++++++++++++++++---------------
 include/console.h |  2 --
 2 files changed, 31 insertions(+), 17 deletions(-)
common/usb_kbd.c +13 -8
index d2d29cc98f..8edeb6c4f5 100644
@@ -516,23 +516,39 @@ static int probe_usb_keyboard(struct usb_device *dev)
                return error;
 
        stdinname = getenv("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;
Quoted 8 lines

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

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

Sorry I should have asked this before: isn't free(devname) OK? In previous version, it has a test logic to see whether free is needed.

Quoted 5 lines

it was in the first version of my patch, until I added the &&!strstr() bit to avoid adding usbkbd a second time to stdin if stdin already contained usbkbd. Now we have a case where stdinname is the ptr returned from getenv() which we probably don't want to free() ;-)

Ah yes, I misread the codes. It's free(newstdin) not free(stdinname). Thanks for the clarification.

Regards,
Bin