Skip to contentSkip to conversation

usb: replace __setup("nousb") with __module_param_call

PATCH Pete Zaitcev 4 participants 12 messages Dec 20, 2005 – Jan 3, 2006 USB

lore
Share & tools
lore
#0 lore raw

Fedora users complain that passing "nousbstorage" to the installer causes the rest of the USB support to disappear. The installer uses kernel command line as a way to pass options through Syslinux. The problem stems from the use of strncmp() in obsolete_checksetup().

I used __module_param_call() instead of module_param because I wanted to preserve the old syntax in grub.conf, and it's the only macro which allows to remove the prefix.

The fix is tested to accept the option "nousb" correctly now.

---

drivers/usb/core/usb.c +1 -12
@@ -54,7 +54,6 @@
 const char *usbcore_name = "usbcore";
 
 static int nousb;	/* Disable USB when built into kernel image */
-			/* Not honored on modular build */
 
 static DECLARE_RWSEM(usb_all_devices_rwsem);
 
@@ -1455,18 +1454,8 @@
 	.resume =	usb_generic_resume,
 };
 
-#ifndef MODULE
-
-static int __init usb_setup_disable(char *str)
-{
-	nousb = 1;
-	return 1;
-}
-
 /* format to disable USB on kernel command line is: nousb */
-__setup("nousb", usb_setup_disable);
-
-#endif
+__module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444);
 
 /*
  * for external read access to <nousb>
#1 lore raw
Quoted 5 lines · Pete Zaitcev

Fedora users complain that passing "nousbstorage" to the installer causes the rest of the USB support to disappear. The installer uses kernel command line as a way to pass options through Syslinux. The problem stems from the use of strncmp() in obsolete_checksetup().

I wonder if that strncmp() should be changed into something like this (untested):

init/main.c +1 -1
@@ -167,7 +167,7 @@ static int __init obsolete_checksetup(ch
 	p = __setup_start;
 	do {
 		int n = strlen(p->str);
-		if (!strncmp(line, p->str, n)) {
+		if (!strncmp(line, p->str, n) && !isalnum(line[n])) {
 			if (p->early) {
 				/* Already done in parse_early_param?  (Needs
 				 * exact match on param part) */
Signature · 1 line
Dmitry
#2 lore raw
Quoted 13 lines · Dmitry Torokhov
Quoted 4 lines · Pete Zaitcev

Fedora users complain that passing "nousbstorage" to the installer causes the rest of the USB support to disappear. The installer uses kernel command line as a way to pass options through Syslinux. The problem stems from the use of strncmp() in obsolete_checksetup().

I wonder if that strncmp() should be changed into something like this (untested):

init/main.c static int __init obsolete_checksetup(ch · line 171

Quoted 6 lines
init/main.c +1 -1
@@ -167,7 +167,7 @@ static int __init obsolete_checksetup(ch
 	p = __setup_start;
 	do {
 		int n = strlen(p->str);
-		if (!strncmp(line, p->str, n)) {
+		if (!strncmp(line, p->str, n) && !isalnum(line[n])) {
 			if (p->early) {

Are you sure that your fix works well in case of __setup("foo=")? It probably breaks all of those.

-- Pete

#3 lore raw
Quoted 11 lines · Pete Zaitcev
Quoted 10 lines · Dmitry Torokhov
Quoted 4 lines · Pete Zaitcev

Fedora users complain that passing "nousbstorage" to the installer causes the rest of the USB support to disappear. The installer uses kernel command line as a way to pass options through Syslinux. The problem stems from the use of strncmp() in obsolete_checksetup().

I wonder if that strncmp() should be changed into something like this (untested):

Quoted 13 lines

init/main.c static int __init obsolete_checksetup(ch · line 171

Quoted 9 lines
init/main.c +1 -1
@@ -167,7 +167,7 @@ static int __init obsolete_checksetup(ch
 	p = __setup_start;
 	do {
 		int n = strlen(p->str);
-		if (!strncmp(line, p->str, n)) {
+		if (!strncmp(line, p->str, n) && !isalnum(line[n])) {
 			if (p->early) {

Are you sure that your fix works well in case of __setup("foo=")? It probably breaks all of those.

Yes, of course you are right. What do you think about the patch below? I think it shoudl handle the case of one option being a prefix for another.

Signature · 75 lines
Dmitry

Signed-off-by: Dmitry Torokhov <[email protected]>
---

 init/main.c |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)

Index: work/init/main.c
===================================================================
--- work.orig/init/main.c
+++ work/init/main.c
@@ -160,24 +160,22 @@ static const char *panic_later, *panic_p
 
 extern struct obs_kernel_param __setup_start[], __setup_end[];
 
-static int __init obsolete_checksetup(char *line)
+static int __init obsolete_checksetup(char *line, int len)
 {
 	struct obs_kernel_param *p;
 
 	p = __setup_start;
 	do {
-		int n = strlen(p->str);
-		if (!strncmp(line, p->str, n)) {
+		if (!strncmp(line, p->str, len) && len == strlen(p->str)) {
 			if (p->early) {
-				/* Already done in parse_early_param?  (Needs
-				 * exact match on param part) */
-				if (line[n] == '\0' || line[n] == '=')
-					return 1;
+				/* Already done in parse_early_param? */
+				return 1;
 			} else if (!p->setup_func) {
-				printk(KERN_WARNING "Parameter %s is obsolete,"
-				       " ignored\n", p->str);
+				printk(KERN_WARNING
+					"Parameter %s is obsolete, ignored\n",
+					p->str);
 				return 1;
-			} else if (p->setup_func(line + n))
+			} else if (p->setup_func(line + len))
 				return 1;
 		}
 		p++;
@@ -226,21 +224,25 @@ __setup("loglevel=", loglevel);
  */
 static int __init unknown_bootoption(char *param, char *val)
 {
+	int len = strlen(param);
+
 	/* Change NUL term back to "=", to make "param" the whole string. */
 	if (val) {
 		/* param=val or param="val"? */
-		if (val == param+strlen(param)+1)
+		if (val == param + len + 1) {
 			val[-1] = '=';
-		else if (val == param+strlen(param)+2) {
+			len++;
+		} else if (val == param + len + 2) {
 			val[-2] = '=';
-			memmove(val-1, val, strlen(val)+1);
+			memmove(val - 1, val, strlen(val) + 1);
 			val--;
+			len++;
 		} else
 			BUG();
 	}
 
 	/* Handle obsolete-style parameters */
-	if (obsolete_checksetup(param))
+	if (obsolete_checksetup(param, len))
 		return 0;
 
 	/*
#4 lore raw

Review

Quoted 4 lines · Dmitry Torokhov
(quoted diff) +2 -2
+static int __init obsolete_checksetup(char *line, int len)
-		int n = strlen(p->str);
-		if (!strncmp(line, p->str, n)) {
+		if (!strncmp(line, p->str, len) && len == strlen(p->str)) {

This looks like it should work, with the disclaimer that I am not infallible.

But even if it does, my patch saved reading, so I think it should be applied as well.

-- Pete

#5 lore raw
Quoted 10 lines · Pete Zaitcev

Review

Quoted 4 lines · Dmitry Torokhov
(quoted diff) +2 -2
+static int __init obsolete_checksetup(char *line, int len)
-             int n = strlen(p->str);
-             if (!strncmp(line, p->str, n)) {
+             if (!strncmp(line, p->str, len) && len == strlen(p->str)) {

This looks like it should work, with the disclaimer that I am not infallible.

;)

Quoted 2 lines

But even if it does, my patch saved reading, so I think it should be applied as well.

What you mean by "saved reading"?

Btw, do we really need to export "nousb" in sysfs?

--
Dmitry

#6 lore raw
Quoted 4 lines · Dmitry Torokhov
Quoted 2 lines

But even if it does, my patch saved reading, so I think it should be applied as well.

What you mean by "saved reading"?

The diffstat was almost all dashes: 13 deletions, 1 addition.

Quoted 1 line

Btw, do we really need to export "nousb" in sysfs?

Nobody would die if we didn't, but there's nothing wrong with the idea in general. At least you'd know that the parameter was actually parsed. I wish usb-handoff was exported similarly, because there's absolutely no way to tell if it worked or was quietly ignored. And I abhor printks in normal or success cases, so I do not want such indication.

-- Pete

#7 lore raw
Quoted 9 lines · Pete Zaitcev
Quoted 4 lines · Dmitry Torokhov
Quoted 2 lines

But even if it does, my patch saved reading, so I think it should be applied as well.

What you mean by "saved reading"?

The diffstat was almost all dashes: 13 deletions, 1 addition.

Quoted 7 lines
Quoted 1 line

Btw, do we really need to export "nousb" in sysfs?

Nobody would die if we didn't, but there's nothing wrong with the idea in general. At least you'd know that the parameter was actually parsed. I wish usb-handoff was exported similarly, because there's absolutely no way to tell if it worked or was quietly ignored. And I abhor printks in normal or success cases, so I do not want such indication.

usb-handoff no longer exists. The kernel now takes USB host controllers away from the BIOS as soon as they are discovered.

Alan Stern

#8 lore raw
Quoted 4 lines · Alan Stern

usb-handoff no longer exists. The kernel now takes USB host controllers away from the BIOS as soon as they are discovered.

Yes! YES! YEEEEES!

*Dmitry dances and rejoices*

--
Dmitry

#11 lore raw
In reply to Alan Stern
Quoted 6 lines · Alan Stern
Quoted 3 lines

I wish usb-handoff was exported similarly, because there's absolutely no way to tell if it worked or was quietly ignored. And I abhor printks in normal or success cases, so I do not want such indication.

usb-handoff no longer exists. The kernel now takes USB host controllers away from the BIOS as soon as they are discovered.

This is why I wrote that I wish that it was exposed or exported. It does not matter now, but it was a good example why the general policy of exposure may be beneficial. English is very confusing.

-- Pete

#9 lore raw
In reply to Dmitry Torokhov
Quoted 9 lines · Dmitry Torokhov
Quoted 4 lines · Alan Stern

usb-handoff no longer exists. The kernel now takes USB host controllers away from the BIOS as soon as they are discovered.

Yes! YES! YEEEEES!

*Dmitry dances and rejoices*

It may not be totally advantageous. Sometimes people have trouble with system installs, when for some reason the USB HID driver doesn't work. If you've got a USB keyboard now you're pretty well stuck, whereas in the past you could specify "nousb" and the BIOS would continue to drive the keyboard.

Alan Stern

#10 lore raw
Quoted 10 lines · Alan Stern
Quoted 8 lines · Dmitry Torokhov
Quoted 4 lines · Alan Stern

usb-handoff no longer exists. The kernel now takes USB host controllers away from the BIOS as soon as they are discovered.

Yes! YES! YEEEEES!

Quoted 8 lines
Quoted 1 line

*Dmitry dances and rejoices*

It may not be totally advantageous. Sometimes people have trouble with system installs, when for some reason the USB HID driver doesn't work. If you've got a USB keyboard now you're pretty well stuck, whereas in the past you could specify "nousb" and the BIOS would continue to drive the keyboard.

Ok, I'd settle with having "usb-handoff" option that defaults to 1. I think if you look at number of problem reports that go away with "usb-handoff" it is sensible default.

--
Dmitry