From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTGZc-00036j-HZ for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTGZa-0008ME-SV for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39655) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTGZa-0008KR-Ks for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:26 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pANHPKFI029010 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 23 Nov 2011 12:25:21 -0500 From: Gerd Hoffmann Date: Wed, 23 Nov 2011 18:25:12 +0100 Message-Id: <1322069117-27150-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1322069117-27150-1-git-send-email-kraxel@redhat.com> References: <1322069117-27150-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 2/7] usb: fix usb_qdev_init error handling. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann qdev doesn't call the ->exit callback on ->init failures, so we have to take care ourself that we cleanup property on errors. Signed-off-by: Gerd Hoffmann --- hw/usb-bus.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index f8b9807..8cafb76 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -9,6 +9,7 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); static char *usb_get_dev_path(DeviceState *dev); static char *usb_get_fw_dev_path(DeviceState *qdev); +static int usb_qdev_exit(DeviceState *qdev); static struct BusInfo usb_bus_info = { .name = "USB", @@ -75,12 +76,23 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base) dev->auto_attach = 1; QLIST_INIT(&dev->strings); rc = usb_claim_port(dev); - if (rc == 0) { - rc = dev->info->init(dev); + if (rc != 0) { + goto err; } - if (rc == 0 && dev->auto_attach) { + rc = dev->info->init(dev); + if (rc != 0) { + goto err; + } + if (dev->auto_attach) { rc = usb_device_attach(dev); + if (rc != 0) { + goto err; + } } + return 0; + +err: + usb_qdev_exit(qdev); return rc; } -- 1.7.1