From patchwork Mon May 10 15:00:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 98419 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4AN9vOb001021 for ; Mon, 10 May 2010 23:09:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933142Ab0EJXCV (ORCPT ); Mon, 10 May 2010 19:02:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45844 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933136Ab0EJXCS (ORCPT ); Mon, 10 May 2010 19:02:18 -0400 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.13.8/8.13.8) with ESMTP id o4AN2Ht6020630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 10 May 2010 19:02:17 -0400 Received: from virtlab9.virt.bos.redhat.com (virtlab9.virt.bos.redhat.com [10.16.72.29]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4AN2GQj015944; Mon, 10 May 2010 19:02:16 -0400 From: Alex Williamson Subject: [PATCH] pci: cleanly backout of pci_qdev_init() To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, alex.williamson@redhat.com Date: Mon, 10 May 2010 11:00:16 -0400 Message-ID: <20100510150016.15398.36521.stgit@virtlab9.virt.bos.redhat.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 10 May 2010 23:09:57 +0000 (UTC) diff --git a/hw/pci.c b/hw/pci.c index f167436..3d3560e 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -625,6 +625,14 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, return pci_dev; } +static void do_pci_unregister_device(PCIDevice *pci_dev) +{ + qemu_free_irqs(pci_dev->irq); + pci_dev->bus->devices[pci_dev->devfn] = NULL; + pci_config_free(pci_dev); + return; +} + PCIDevice *pci_register_device(PCIBus *bus, const char *name, int instance_size, int devfn, PCIConfigReadFunc *config_read, @@ -680,10 +688,7 @@ static int pci_unregister_device(DeviceState *dev) return ret; pci_unregister_io_regions(pci_dev); - - qemu_free_irqs(pci_dev->irq); - pci_dev->bus->devices[pci_dev->devfn] = NULL; - pci_config_free(pci_dev); + do_pci_unregister_device(pci_dev); return 0; } @@ -1652,8 +1657,10 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base) if (pci_dev == NULL) return -1; rc = info->init(pci_dev); - if (rc != 0) + if (rc != 0) { + do_pci_unregister_device(pci_dev); return rc; + } /* rom loading */ if (pci_dev->romfile == NULL && info->romfile != NULL)