qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [usb] redo usb_host_find_device() routine - strtoul returning 0 for bus_num
@ 2006-05-25  3:24 Lonnie Mendez
       [not found] ` <449031FC.3060100@bellard.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Lonnie Mendez @ 2006-05-25  3:24 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 287 bytes --]

   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.

[-- Attachment #2: qemu-usb-linux.diff --]
[-- Type: text/plain, Size: 1326 bytes --]

--- 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;
 }
 
 /**********************/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-06-15  5:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-25  3:24 [Qemu-devel] [usb] redo usb_host_find_device() routine - strtoul returning 0 for bus_num Lonnie Mendez
     [not found] ` <449031FC.3060100@bellard.org>
2006-06-15  5:47   ` Lonnie Mendez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).