From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SmHNK-0006vP-DF for qemu-devel@nongnu.org; Wed, 04 Jul 2012 00:39:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SmHNI-0002DA-MQ for qemu-devel@nongnu.org; Wed, 04 Jul 2012 00:39:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SmHNI-0002D0-EX for qemu-devel@nongnu.org; Wed, 04 Jul 2012 00:39:36 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q644dZj6024224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 4 Jul 2012 00:39:35 -0400 From: Alex Williamson Date: Tue, 03 Jul 2012 22:39:34 -0600 Message-ID: <20120704043933.19100.80886.stgit@bling.home> In-Reply-To: <20120704041748.19100.95271.stgit@bling.home> References: <20120704041748.19100.95271.stgit@bling.home> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 2/2] pci: Unregister BARs before device exit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mst@redhat.com Cc: qemu-devel@nongnu.org BARs are registered in init functions from memory regions created by the drivers. Exit functions destroy those memory regions. By unregistering the io regions after exit(), we're calling memory_region_del_subregion on freed memory. Don't do that. The option rom comes along for the ride because it's more symmetric to how it's created. Signed-off-by: Alex Williamson --- hw/pci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 8934722..1fc73f8 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -875,12 +875,13 @@ static int pci_unregister_device(DeviceState *dev) PCIDevice *pci_dev = PCI_DEVICE(dev); PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev); + pci_unregister_io_regions(pci_dev); + pci_del_option_rom(pci_dev); + if (pc->exit) { pc->exit(pci_dev); } - pci_unregister_io_regions(pci_dev); - pci_del_option_rom(pci_dev); do_pci_unregister_device(pci_dev); return 0; }