From patchwork Mon May 2 18:00:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 93688 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 80D43B6F0A for ; Tue, 3 May 2011 04:01:05 +1000 (EST) Received: from localhost ([::1]:49280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGxQc-0001bc-0P for incoming@patchwork.ozlabs.org; Mon, 02 May 2011 14:01:02 -0400 Received: from eggs.gnu.org ([140.186.70.92]:45557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGxQT-0001bJ-7S for qemu-devel@nongnu.org; Mon, 02 May 2011 14:00:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QGxQS-0006Ey-2q for qemu-devel@nongnu.org; Mon, 02 May 2011 14:00:53 -0400 Received: from goliath.siemens.de ([192.35.17.28]:21262) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGxQR-0006Es-Nw for qemu-devel@nongnu.org; Mon, 02 May 2011 14:00:52 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id p42I0mgs012458; Mon, 2 May 2011 20:00:48 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p42I0lfr000739; Mon, 2 May 2011 20:00:48 +0200 Message-ID: <4DBEF14F.3010505@siemens.com> Date: Mon, 02 May 2011 20:00:47 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: qemu-devel References: <4DBE75D5.8050901@siemens.com> In-Reply-To: <4DBE75D5.8050901@siemens.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.28 Cc: "Michael S. Tsirkin" , Alexander Graf , Gerd Hoffmann Subject: [Qemu-devel] [PATCH v2] MSI: Robust resource release 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 msi_init may fail, so we need to check on uninit if the cap was actually installed. This also avoids that the users need to check. Signed-off-by: Jan Kiszka Acked-by: Alexander Graf --- hw/ide/ich.c | 5 +---- hw/intel-hda.c | 4 +--- hw/msi.c | 12 ++++++++++-- 3 files changed, 12 insertions(+), 9 deletions(-) v2: Push cap check into msi_uninit (just like msix), remove check from users. diff --git a/hw/ide/ich.c b/hw/ide/ich.c index a3d475c..8c1ff6c 100644 --- a/hw/ide/ich.c +++ b/hw/ide/ich.c @@ -110,10 +110,7 @@ static int pci_ich9_uninit(PCIDevice *dev) struct AHCIPCIState *d; d = DO_UPCAST(struct AHCIPCIState, card, dev); - if (msi_enabled(dev)) { - msi_uninit(dev); - } - + msi_uninit(dev); qemu_unregister_reset(ahci_reset, d); ahci_uninit(&d->ahci); diff --git a/hw/intel-hda.c b/hw/intel-hda.c index b0b1d12..093c4b9 100644 --- a/hw/intel-hda.c +++ b/hw/intel-hda.c @@ -1174,9 +1174,7 @@ static int intel_hda_exit(PCIDevice *pci) { IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci); - if (d->msi) { - msi_uninit(&d->pci); - } + msi_uninit(&d->pci); cpu_unregister_io_memory(d->mmio_addr); return 0; } diff --git a/hw/msi.c b/hw/msi.c index 0cbf89f..3141804 100644 --- a/hw/msi.c +++ b/hw/msi.c @@ -183,9 +183,17 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, void msi_uninit(struct PCIDevice *dev) { - uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); - uint8_t cap_size = msi_cap_sizeof(flags); + uint16_t flags; + uint8_t cap_size; + + if (!(dev->cap_present & QEMU_PCI_CAP_MSI)) { + return; + } + flags = pci_get_word(dev->config + msi_flags_off(dev)); + cap_size = msi_cap_sizeof(flags); pci_del_capability(dev, PCI_CAP_ID_MSIX, cap_size); + dev->cap_present &= ~QEMU_PCI_CAP_MSI; + MSI_DEV_PRINTF(dev, "uninit\n"); }