sim-card
/
qemu
Archived
10
0
Fork 0

Fix recently introduced bugs in -usbdevice host

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>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Markus Armbruster 2009-11-27 13:05:53 +01:00 committed by Anthony Liguori
parent 21eb3a2ba3
commit 0745eb1e43
1 changed files with 16 additions and 12 deletions

View File

@ -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, ":.");