From patchwork Wed Feb 18 07:12:51 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Han, Weidong" X-Patchwork-Id: 7712 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n1I7E53a031632 for ; Wed, 18 Feb 2009 07:14:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752802AbZBRHOC (ORCPT ); Wed, 18 Feb 2009 02:14:02 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752793AbZBRHOC (ORCPT ); Wed, 18 Feb 2009 02:14:02 -0500 Received: from mga09.intel.com ([134.134.136.24]:55568 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752610AbZBRHOA (ORCPT ); Wed, 18 Feb 2009 02:14:00 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 17 Feb 2009 23:07:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.38,227,1233561600"; d="scan'208,223";a="387703317" Received: from unknown (HELO azsmsx601.amr.corp.intel.com) ([10.2.121.193]) by orsmga002.jf.intel.com with ESMTP; 17 Feb 2009 23:22:47 -0800 Received: from pdsmsx601.ccr.corp.intel.com (172.16.12.94) by azsmsx601.amr.corp.intel.com (10.2.121.193) with Microsoft SMTP Server (TLS) id 8.1.311.2; Wed, 18 Feb 2009 00:13:27 -0700 Received: from pdsmsx503.ccr.corp.intel.com ([172.16.12.95]) by pdsmsx601.ccr.corp.intel.com ([172.16.12.94]) with mapi; Wed, 18 Feb 2009 15:12:53 +0800 From: "Han, Weidong" To: "'Avi Kivity'" CC: "'kvm@vger.kernel.org'" , "'Mark McLoughlin'" , "'Marcelo Tosatti'" Date: Wed, 18 Feb 2009 15:12:51 +0800 Subject: [PATCH 5/8] kvm: qemu: free device on error in init_assigned_device Thread-Topic: [PATCH 5/8] kvm: qemu: free device on error in init_assigned_device Thread-Index: AcmRmE+wiQGodBjZSV+64IWkoFU+XQ== Message-ID: <715D42877B251141A38726ABF5CABF2C0195A1F9B4@pdsmsx503.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org make init_assigned_device call free_assigned_device on error, and then make free_assigned_device is static because it's only invoked in device-assigned.c. Acked-by: Mark McLoughlin Signed-off-by: Weidong Han --- qemu/hw/device-assignment.c | 12 ++++++++---- qemu/hw/device-assignment.h | 1 - qemu/hw/pci-hotplug.c | 1 - 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c index e6d2352..6046fdd 100644 --- a/qemu/hw/device-assignment.c +++ b/qemu/hw/device-assignment.c @@ -443,7 +443,7 @@ again: static LIST_HEAD(, AssignedDevInfo) adev_head; -void free_assigned_device(AssignedDevInfo *adev) +static void free_assigned_device(AssignedDevInfo *adev) { AssignedDevice *dev = adev->assigned_dev; @@ -558,14 +558,14 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus) if (get_real_device(dev, adev->bus, adev->dev, adev->func)) { fprintf(stderr, "%s: Error: Couldn't get real device (%s)!\n", __func__, adev->name); - return NULL; + goto out; } /* handle real device's MMIO/PIO BARs */ if (assigned_dev_register_regions(dev->real_device.regions, dev->real_device.region_number, dev)) - return NULL; + goto out; /* handle interrupt routing */ e_device = (dev->dev.devfn >> 3) & 0x1f; @@ -595,10 +595,14 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus) if (r < 0) { fprintf(stderr, "Failed to assign device \"%s\" : %s\n", adev->name, strerror(-r)); - return NULL; + goto out; } return &dev->dev; + +out: + free_assigned_device(adev); + return NULL; } /* diff --git a/qemu/hw/device-assignment.h b/qemu/hw/device-assignment.h index f216bb0..6a9b9fa 100644 --- a/qemu/hw/device-assignment.h +++ b/qemu/hw/device-assignment.h @@ -94,7 +94,6 @@ struct AssignedDevInfo { int disable_iommu; }; -void free_assigned_device(AssignedDevInfo *adev); PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus); AssignedDevInfo *add_assigned_device(const char *arg); void add_assigned_devices(PCIBus *bus, const char **devices, int n_devices); diff --git a/qemu/hw/pci-hotplug.c b/qemu/hw/pci-hotplug.c index 8c76453..65fafd1 100644 --- a/qemu/hw/pci-hotplug.c +++ b/qemu/hw/pci-hotplug.c @@ -143,7 +143,6 @@ static PCIDevice *qemu_pci_hot_assign_device(PCIBus *pci_bus, const char *opts) ret = init_assigned_device(adev, pci_bus); if (ret == NULL) { term_printf("Failed to assign device\n"); - free_assigned_device(adev); return NULL; }