From patchwork Wed Jul 4 04:39:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 168886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AC7F22C0088 for ; Wed, 4 Jul 2012 14:40:06 +1000 (EST) Received: from localhost ([::1]:38094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SmHNk-0007rr-JB for incoming@patchwork.ozlabs.org; Wed, 04 Jul 2012 00:40:04 -0400 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 Received: from bling.home (ovpn-113-149.phx2.redhat.com [10.3.113.149]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q644dYjC030731; Wed, 4 Jul 2012 00:39:34 -0400 From: Alex Williamson To: mst@redhat.com 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> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 2/2] pci: Unregister BARs before device exit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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; }