qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [usb] redo usb_host_find_device() routine - strtoul returni


From: Lonnie Mendez
Subject: [Qemu-devel] [usb] redo usb_host_find_device() routine - strtoul returning 0 for bus_num
Date: Wed, 24 May 2006 22:24:57 -0500
User-agent: Mozilla Thunderbird 1.0.7 (X11/20050923)

  lo list.  Trying usb_add host:3.2 was failing with:

/proc/bus/usb/000/002: No such file or directory

in the terminal that qemu was spawned from. It looks like strtoul was returning 0 for bus_num with the devname "host:3.2". I rewrote the function to use sscanf in both cases.
--- qemu/usb-linux.c    2006-03-11 12:03:38.000000000 -0600
+++ qemu/usb-linux.c    2006-05-24 21:53:20.000000000 -0500
@@ -361,28 +377,23 @@
 static int usb_host_find_device(int *pbus_num, int *paddr, 
                                 const char *devname)
 {
-    const char *p;
-    int ret;
     FindDeviceState fs;
 
-    p = strchr(devname, '.');
-    if (p) {
-        *pbus_num = strtoul(devname, NULL, 0);
-        *paddr = strtoul(p + 1, NULL, 0);
-        return 0;
-    }
-    p = strchr(devname, ':');
-    if (p) {
-        fs.vendor_id = strtoul(devname, NULL, 16);
-        fs.product_id = strtoul(p + 1, NULL, 16);
-        ret = usb_host_scan(&fs, usb_host_find_device_scan);
-        if (ret) {
-            *pbus_num = fs.bus_num;
-            *paddr = fs.addr;
-            return 0;
+    if (sscanf(devname, "host:%03d.%03d", pbus_num, paddr) != 2) {
+        if (sscanf(devname, "host:%04x:%04x", &fs.vendor_id, &fs.product_id) 
== 2) {
+            if (usb_host_scan(&fs, usb_host_find_device_scan)) {
+                *pbus_num = fs.bus_num;
+                *paddr = fs.addr;
+                return 0;
+            } else {
+                return -1;
+            }
+        } else {
+            return -1;
         }
+    } else {
+        return 0;
     }
-    return -1;
 }
 
 /**********************/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]