misc/163986: avoid reloading modules in devd for usb devices

Robert Nagy robert at nerd.hu
Tue Jan 10 12:00:24 UTC 2012

>Number:         163986
>Category:       misc
>Synopsis:       avoid reloading modules in devd for usb devices
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 10 12:00:24 UTC 2012
>Originator:     Robert Nagy
>Release:        FreeBSD 9.0-RC3 amd64
FreeBSD x200s.humppa.hu 9.0-RC3 FreeBSD 9.0-RC3 #0: Sun Dec 4 08:56:36 UTC 2011 root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
devd tries to reload kernel modules which are loaded already because of multiple already-attached devices
in a system. e.g.: umodem, ng_ubt.

This causes a lot of error messages on boot which is quiet annoying.

boot any machine with multiple usb devices attached to it
Only try to load the module if it's not loaded already.
The attached patch adds a quiet feature to kldstat's -n flag so that we can rely on just the return values of kldstat and load based on that in the action fields of /etc/devd/usb.conf.

The diff does not actually include the generated usb.conf because that would have been too big for the attachment.

Patch attached with submission follows:

Index: sbin/kldstat/kldstat.c
--- sbin/kldstat/kldstat.c	(revision 229928)
+++ sbin/kldstat/kldstat.c	(working copy)
@@ -146,8 +146,12 @@
     if (filename != NULL) {
-	if ((fileid = kldfind(filename)) < 0)
-	    err(1, "can't find file %s", filename);
+	if ((fileid = kldfind(filename)) < 0) {
+	    if (!quiet)
+		warn("can't find file %s", filename);
+	    return 1;
+	} else if (quiet)
+	    return 0;
     printf("Id Refs Address%*c Size     Name\n", POINTER_WIDTH - 7, ' ');
Index: sbin/kldstat/kldstat.8
--- sbin/kldstat/kldstat.8	(revision 229928)
+++ sbin/kldstat/kldstat.8	(working copy)
@@ -35,10 +35,12 @@
 .Op Fl v
 .Op Fl i Ar id
-.Op Fl n Ar filename
 .Op Fl q
 .Op Fl m Ar modname
+.Op Fl qv
+.Op Fl n Ar filename
Index: tools/tools/bus_autoconf/bus_usb.c
--- tools/tools/bus_autoconf/bus_usb.c	(revision 229928)
+++ tools/tools/bus_autoconf/bus_usb.c	(working copy)
@@ -317,8 +317,8 @@
 		printf("	match \"intprotocol\" \"0x%02x\";\n",
-	printf("	action \"kldload %s\";\n"
-	    "};\n\n", id->module_name);
+	printf("	action \"kldstat -qn %s || kldload %s\";\n"
+	    "};\n\n", id->module_name, id->module_name);
 	return (n);


More information about the freebsd-bugs mailing list