From patchwork Fri Nov 27 12:05:53 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 39628 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0A7771007D1 for ; Fri, 27 Nov 2009 23:49:33 +1100 (EST) Received: from localhost ([127.0.0.1]:54677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NE0GP-0003ST-Op for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2009 07:49:29 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NE06l-0006RD-KA for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:39:32 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NE06e-0006Oc-8e for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:39:28 -0500 Received: from [199.232.76.173] (port=52503 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NE06d-0006OO-Jy for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:39:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35835) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NE06d-0008Bf-5V for qemu-devel@nongnu.org; Fri, 27 Nov 2009 07:39:23 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nARCdMmF014535 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 27 Nov 2009 07:39:22 -0500 Received: from crossbow.pond.sub.org (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nARCdLQf005087 for ; Fri, 27 Nov 2009 07:39:21 -0500 Received: by crossbow.pond.sub.org (Postfix, from userid 500) id 5117E25ABF; Fri, 27 Nov 2009 13:39:20 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 27 Nov 2009 13:05:53 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH] Fix recently introduced bugs in -usbdevice host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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, ":.");