Patchwork [2/2] Return usb device to host on exit

login
register
mail settings
Submitter Shahar Havivi
Date June 12, 2010, 9:59 a.m.
Message ID <c1f8a92e3cfc5da8456852a308cc3911b29af67f.1276335589.git.shaharh@redhat.com>
Download mbox | patch
Permalink /patch/55385/
State New
Headers show

Comments

Shahar Havivi - June 12, 2010, 9:59 a.m.
Signed-off-by: Shahar Havivi <shaharh@redhat.com>
---
 usb-linux.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
Gerd Hoffmann - June 14, 2010, 9:50 a.m.
> @@ -1066,6 +1077,7 @@ USBDevice *usb_host_device_open(const char *devname)
>       qdev_prop_set_uint32(&dev->qdev, "vendorid",  filter.vendor_id);
>       qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id);
>       qdev_init_nofail(&dev->qdev);
> +    atexit(usb_host_cleanup);
>       return dev;

You'll register atexit multiple times here (once per device).

I still think this should use exit notifiers, see 
http://patchwork.ozlabs.org/patch/54571/ (doesn't apply cleanly and 
more, will post a rebased version later today).

cheers,
   Gerd

Patch

diff --git a/usb-linux.c b/usb-linux.c
index 22a85e3..2a595f0 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -286,6 +286,17 @@  static void async_cancel(USBPacket *unused, void *opaque)
     }
 }
 
+static void usb_host_cleanup(void)
+{
+    struct USBHostDevice *s;
+
+    QTAILQ_FOREACH(s, &hostdevs, next) {
+        if (s->fd != -1) {
+            ioctl(s->fd, USBDEVFS_RESET);
+        }
+    }
+}
+
 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
     int dev_descr_len, config_descr_len;
@@ -1066,6 +1077,7 @@  USBDevice *usb_host_device_open(const char *devname)
     qdev_prop_set_uint32(&dev->qdev, "vendorid",  filter.vendor_id);
     qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id);
     qdev_init_nofail(&dev->qdev);
+    atexit(usb_host_cleanup);
     return dev;
 
 fail: