From ak03@gte.com  Tue Jan  8 15:12:29 2002
Return-Path: <ak03@gte.com>
Received: from h132-197-179-27.gte.com (h132-197-179-27.gte.com [132.197.179.27])
	by hub.freebsd.org (Postfix) with ESMTP
	id 774E537B41F; Tue,  8 Jan 2002 15:12:28 -0800 (PST)
Received: (from ak03@localhost)
	by h132-197-179-27.gte.com (8.11.6/8.11.4) id g08NCRR86733;
	Tue, 8 Jan 2002 18:12:27 -0500 (EST)
	(envelope-from ak03)
Message-Id: <200201082312.g08NCRR86733@h132-197-179-27.gte.com>
Date: Tue, 8 Jan 2002 18:12:27 -0500 (EST)
From: "Alexander N. Kabaev" <ak03@gte.com>
Reply-To: "Alexander N. Kabaev" <ak03@gte.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Josef Karthauser <joe@freebsd.org>
Subject: Duplicate make_dev panic in ugen.c + patch
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         33712
>Category:       kern
>Synopsis:       Duplicate make_dev panic in ugen.c + patch
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    joe
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 08 15:20:01 PST 2002
>Closed-Date:    Mon Jul 22 12:22:48 PDT 2002
>Last-Modified:  Mon Jul 22 12:22:48 PDT 2002
>Originator:     Alexander N. Kabaev
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Verizon Data Services
>Environment:
System: FreeBSD kanpc.gte.com 5.0-CURRENT FreeBSD 5.0-CURRENT #20: Mon Jan 7 17:20:17 EST 2002 root@kanpc.gte.com:/usr/src/sys/i386/compile/KANPC i386


	
>Description:
	It is possible to get the "duplicate make_dev: Don't do that" panic
	in ugen.c if USB device has not been recognised or is failed to attach 
	for the first time, because ugen_attach functions always attempts
	to create make_dev but fails to clean-up after itself on failure.
>How-To-Repeat:
	Get crappy motherboard with which USB interrupt delivery is not working
	at the hardware probing time but works just fine as soon an system
	reaches multi-user mode and buy a Microsoft IntelliMouse USB?
	Interrupts problem will be reported separately.
>Fix:

	Proposed patch moves control device node creation/destruction
	into ugen_make_devnodes/ugen_destroy_devnodes functions
	respectively. This way device nodes are not created unless
	device probe is finished successfully and the whole problem
	is just eliminated. Also has nice side effect of removing
	some ugly __FreeBSD__ ifdefs.

Index: ugen.c
===================================================================
RCS file: /usr/ncvs/src/sys/dev/usb/ugen.c,v
retrieving revision 1.56
diff -u -r1.56 ugen.c
--- ugen.c	2 Jan 2002 23:31:08 -0000	1.56
+++ ugen.c	8 Jan 2002 22:52:44 -0000
@@ -202,11 +202,6 @@
 
 	sc->sc_udev = udev = uaa->device;
 
-#if defined(__FreeBSD__)
-	/* the main device, ctrl endpoint */
-	make_dev(&ugen_cdevsw, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0),
-		UID_ROOT, GID_OPERATOR, 0644, "%s", USBDEVNAME(sc->sc_dev));
-#endif
 	memset(sc->sc_endpoints, 0, sizeof sc->sc_endpoints);
 
 	/* First set configuration index 0, the default one for ugen. */
@@ -237,6 +232,10 @@
 {
 	int endptno;
 
+	/* the main device, ctrl endpoint */
+	make_dev(&ugen_cdevsw, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0),
+		UID_ROOT, GID_OPERATOR, 0644, "%s", USBDEVNAME(sc->sc_dev));
+
 	for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++) {
 		if (sc->sc_endpoints[endptno][IN].sc != NULL ||
 		    sc->sc_endpoints[endptno][OUT].sc != NULL ) {
@@ -264,6 +263,13 @@
 	dev_t dev;
 	struct vnode *vp;
 
+	/* destroy the device for the control endpoint */
+	dev = makedev(UGEN_CDEV_MAJOR, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0));
+	vp = SLIST_FIRST(&dev->si_hlist);
+	if (vp)
+		VOP_REVOKE(vp, REVOKEALL);
+	destroy_dev(dev);
+
 	/* destroy all devices for the other (existing) endpoints as well */
 	for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++) {
 		if (sc->sc_endpoints[endptno][IN].sc != NULL ||
@@ -816,9 +822,6 @@
 	int s;
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 	int maj, mn;
-#elif defined(__FreeBSD__)
-	dev_t dev;
-	struct vnode *vp;
 #endif
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
@@ -857,12 +860,6 @@
 	mn = self->dv_unit * USB_MAX_ENDPOINTS;
 	vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);
 #elif defined(__FreeBSD__)
-	/* destroy the device for the control endpoint */
-	dev = makedev(UGEN_CDEV_MAJOR, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0));
-	vp = SLIST_FIRST(&dev->si_hlist);
-	if (vp)
-		VOP_REVOKE(vp, REVOKEALL);
-	destroy_dev(dev);
 	ugen_destroy_devnodes(sc);
 #endif
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->joe 
Responsible-Changed-By: joe 
Responsible-Changed-When: Tue Jan 8 15:21:06 PST 2002 
Responsible-Changed-Why:  
I'll take this.  Thanks. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33712 

From: "Alexander N. Kabaev" <ak03@gte.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/33712: Duplicate make_dev panic in ugen.c + patch
Date: Tue, 14 May 2002 10:40:08 -0400

 Please ignore the patch in this PR. It stops panics if ugen attach 
 fails, but introduces a new one if
 attach was successfull.
 
 Or close this PR altogether.
 
State-Changed-From-To: open->closed 
State-Changed-By: kan 
State-Changed-When: Mon Jul 22 12:21:28 PDT 2002 
State-Changed-Why:  
The patch is bogus. The problem has been dealt with in a better 
way. Closed at originator request. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=33712 
>Unformatted:
