Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Oct 2003 20:10:25 +1000
From:      Johny Mattsson <lonewolf-freebsd@earthmagic.org>
To:        freebsd-current@freebsd.org
Subject:   USB device detach events [PATCH - please test]
Message-ID:  <3F950611.8080302@earthmagic.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------040900000008030903040403
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

As an answer to my previous email, I now have patches fixing the missing 
USB device detach events. This works extremely well on my system, but 
it'd be great if I could get some wider exposure before I send-pr them. 
 From my perusal/grepping of all the usb drivers, these patches 
shouldn't break anything, only allow usbd to receive DEVICE_DETACH 
events for all devices.


When I continued chasing my original problem, I discovered that the 
usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev) call in usb_subr.c was 
commented out. Bringing it back into play brought me a nice solid system 
freeze, followed by a reboot shortly thereafter. I figure that must be 
why it was commented out in the first place.

As it turns out, the placement of that call is really bad. The 'dev' it 
hands out is in an inconsistent state if any subdevs existed (if there 
were no subdevs, everything works fine). I say existed, because at the 
original location of the "add event" call, the subdevs have already been 
detached. The usbd_add_dev_event function however calls the 
usbd_fill_deviceinfo, which wants to fiddle with the subdevs as well, 
resulting in Bad Things happening. My patch to usb_subr.c simply moves 
the usbd_add_dev_event call to just before the subdevs are disconnected.

Also, the patch to usb.c guarantees (I believe) that if a DRIVER_DETACH 
event is added to the queue before the DEVICE_DETACH event has been 
processed, the DEVICE_DETACH is kept on the queue, resulting in expected 
behaviour by usbd.

Comments are welcome. If I don't hear anything from anyone, I'll send-pr 
in a couple of days.

Cheers,
/Johny
-- 
Johny Mattsson - System Designer ,-.   ,-.   ,-.  There is no truth.
http://www.earthmagic.org     _.'  `-'   `-'  There is only perception.

--------------040900000008030903040403
Content-Type: text/plain;
 name="usb_subr.c.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="usb_subr.c.patch"

--- usb_subr.c.org	Tue Oct 21 17:44:48 2003
+++ usb_subr.c	Tue Oct 21 19:40:44 2003
@@ -1353,6 +1353,8 @@
 	}
 #endif
 
+	usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev);
+
 	if (dev->subdevs != NULL) {
 		DPRINTFN(3,("usb_disconnect_port: disconnect subdevs\n"));
 		for (i = 0; dev->subdevs[i]; i++) {
@@ -1365,7 +1367,6 @@
 		}
 	}
 
-	/*usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev);*/
 	dev->bus->devices[dev->address] = NULL;
 	up->device = NULL;
 	usb_free_device(dev);

--------------040900000008030903040403
Content-Type: text/plain;
 name="usb.c.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="usb.c.patch"

--- usb.c.org	Tue Oct 21 16:51:25 2003
+++ usb.c	Tue Oct 21 19:42:00 2003
@@ -781,7 +781,8 @@
 		for (ueqi = TAILQ_FIRST(&usb_events); ueqi; ueqi = ueqi_next) {
 			ueqi_next = TAILQ_NEXT(ueqi, next);
 			if (ueqi->ue.u.ue_driver.ue_cookie.cookie ==
-			    uep->u.ue_device.udi_cookie.cookie) {
+			    uep->u.ue_device.udi_cookie.cookie &&
+			    !USB_EVENT_IS_DETACH(ueqi->ue.ue_type)) {
 				TAILQ_REMOVE(&usb_events, ueqi, next);
 				free(ueqi, M_USBDEV);
 				usb_nevents--;

--------------040900000008030903040403--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3F950611.8080302>