]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] USB devio device removal fix
authorDavid Brownell <david-b@pacbell.net>
Fri, 12 Apr 2002 03:41:00 +0000 (20:41 -0700)
committerGreg Kroah-Hartman <greg@kroah.com>
Fri, 12 Apr 2002 03:41:00 +0000 (20:41 -0700)
USB devio device removal fix

Fixes problem with using usbfs and a device is removed while the
device still has pending events.

drivers/usb/core/devio.c

index d6df3e30e60370fa6f993f8d801807979ba50c3e..3e06620b8bef24a9f4a176e124c288824090fc02 100644 (file)
@@ -297,7 +297,9 @@ static void destroy_all_async(struct dev_state *ps)
 }
 
 /*
- * interface claiming
+ * interface claims are made only at the request of user level code,
+ * which can also release them (explicitly or by closing files).
+ * they're also undone when devices disconnect.
  */
 
 static void *driver_probe(struct usb_device *dev, unsigned int intf,
@@ -310,8 +312,20 @@ static void driver_disconnect(struct usb_device *dev, void *context)
 {
        struct dev_state *ps = (struct dev_state *)context;
 
-       if (ps)
-               ps->ifclaimed = 0;
+       if (!ps)
+               return;
+
+       /* this waits till synchronous requests complete */
+       down_write (&ps->devsem);
+
+       /* prevent new I/O requests */
+       ps->dev = 0;
+       ps->ifclaimed = 0;
+
+       /* force async requests to complete */
+       destroy_all_async (ps);
+
+       up_write (&ps->devsem);
 }
 
 struct usb_driver usbdevfs_driver = {