All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Fix recently introduced bugs in -usbdevice host
Date: Fri, 27 Nov 2009 13:05:53 +0100	[thread overview]
Message-ID: <m33a40f8g7.fsf@crossbow.pond.sub.org> (raw)

Commit 26a9e82a has the following flaws:

* It enabled DEBUG.

* It referenced two properties by the wrong name in
  usb_host_device_open(), which crashes with "qdev_prop_set: property
  "USB Host Device.bus" not found".

* It broke "-usbdevice host:auto:..." by calling parse_filter()
  incorrectly.

* It broke parsing of "-usbdevice host:BUS.ADDR" and "-usbdevice
  host:VID:PRID" with a trivial pasto.

* It broke wildcards in "-usbdevice host:auto:...".  Before, the four
  filter components were stored as int, and the wildcard was encoded
  as -1.  The faulty commit changed storage to uint32_t, and the
  wildcard encoding to 0.  But it failed to update parse_filter()
  accordingly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
If you want me to split this up into one patch per bug, I can do that.

 usb-linux.c |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 96f9a27..285ac22 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -65,7 +65,7 @@ typedef int USBScanFunc(void *opaque, int bus_num, int addr, int class_id,
                         int vendor_id, int product_id,
                         const char *product_name, int speed);
 
-#define DEBUG
+//#define DEBUG
 
 #ifdef DEBUG
 #define dprintf printf
@@ -1005,7 +1005,7 @@ device_init(usb_host_register_devices)
 
 USBDevice *usb_host_device_open(const char *devname)
 {
-    struct USBAutoFilter filter = { 0, 0, 0, 0 };
+    struct USBAutoFilter filter;
     USBDevice *dev;
     USBHostDevice *s;
     char *p;
@@ -1014,22 +1014,26 @@ USBDevice *usb_host_device_open(const char *devname)
     s = DO_UPCAST(USBHostDevice, dev, dev);
 
     if (strstr(devname, "auto:")) {
-        if (parse_filter(devname+5, &filter) < 0)
+        if (parse_filter(devname, &filter) < 0)
             goto fail;
     } else {
         if ((p = strchr(devname, '.'))) {
-            filter.bus_num = strtoul(devname, NULL, 0);
-            filter.addr    = strtoul(devname, NULL, 0);
+            filter.bus_num    = strtoul(devname, NULL, 0);
+            filter.addr       = strtoul(p + 1, NULL, 0);
+            filter.vendor_id  = 0;
+            filter.product_id = 0;
         } else if ((p = strchr(devname, ':'))) {
+            filter.bus_num    = 0;
+            filter.addr       = 0;
             filter.vendor_id  = strtoul(devname, NULL, 16);
-            filter.product_id = strtoul(devname, NULL, 16);
+            filter.product_id = strtoul(p + 1, NULL, 16);
         } else {
             goto fail;
         }
     }
 
-    qdev_prop_set_uint32(&dev->qdev, "bus",       filter.bus_num);
-    qdev_prop_set_uint32(&dev->qdev, "addr",      filter.addr);
+    qdev_prop_set_uint32(&dev->qdev, "hostbus",   filter.bus_num);
+    qdev_prop_set_uint32(&dev->qdev, "hostaddr",  filter.addr);
     qdev_prop_set_uint32(&dev->qdev, "vendorid",  filter.vendor_id);
     qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id);
     qdev_init(&dev->qdev);
@@ -1449,10 +1453,10 @@ static int parse_filter(const char *spec, struct USBAutoFilter *f)
     const char *p = spec;
     int i;
 
-    f->bus_num    = -1;
-    f->addr       = -1;
-    f->vendor_id  = -1;
-    f->product_id = -1;
+    f->bus_num    = 0;
+    f->addr       = 0;
+    f->vendor_id  = 0;
+    f->product_id = 0;
 
     for (i = BUS; i < DONE; i++) {
     	p = strpbrk(p, ":.");
-- 
1.6.2.5

             reply	other threads:[~2009-11-27 12:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-27 12:05 Markus Armbruster [this message]
2009-11-27 13:40 ` [Qemu-devel] [PATCH] Fix recently introduced bugs in -usbdevice host Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m33a40f8g7.fsf@crossbow.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.