From patchwork Tue Sep 8 14:10:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 515412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 56739140187 for ; Wed, 9 Sep 2015 00:11:19 +1000 (AEST) Received: from localhost ([::1]:34607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZJcD-0006o8-Bb for incoming@patchwork.ozlabs.org; Tue, 08 Sep 2015 10:11:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZJbH-0005bN-3L for qemu-devel@nongnu.org; Tue, 08 Sep 2015 10:10:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZJbC-00016d-Kn for qemu-devel@nongnu.org; Tue, 08 Sep 2015 10:10:18 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:49188) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZJbC-00016L-ER for qemu-devel@nongnu.org; Tue, 08 Sep 2015 10:10:14 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t88EA6bZ024333 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Sep 2015 14:10:07 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t88EA613017652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 8 Sep 2015 14:10:06 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t88EA6OP010221; Tue, 8 Sep 2015 14:10:06 GMT Received: from l.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 08 Sep 2015 07:10:06 -0700 Received: by l.oracle.com (Postfix, from userid 1000) id 751496A4B9E; Tue, 8 Sep 2015 10:10:04 -0400 (EDT) From: Konrad Rzeszutek Wilk To: stefano.stabellini@eu.citrix.com, xen-devel@lists.xenproject.org, qemu-devel@nongnu.org Date: Tue, 8 Sep 2015 10:10:01 -0400 Message-Id: <1441721402-12464-10-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1441721402-12464-1-git-send-email-konrad.wilk@oracle.com> References: <1441721402-12464-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 Cc: JBeulich@suse.com, Konrad Rzeszutek Wilk Subject: [Qemu-devel] [PATCH v2 09/10] xen/pt: Check for return values for xen_host_pci_[get|set] in init 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 and if we have failures we call xen_pt_destroy introduced in 'xen/pt: Move bulk of xen_pt_unregister_device in its own routine.' and free all of the allocated structures. Acked-by: Stefano Stabellini Signed-off-by: Konrad Rzeszutek Wilk --- hw/xen/xen_pt.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 5a49a86..80b687f 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -774,10 +774,11 @@ static int xen_pt_initfn(PCIDevice *d) } /* Initialize virtualized PCI configuration (Extended 256 Bytes) */ - if (xen_host_pci_get_block(&s->real_device, 0, d->config, - PCI_CONFIG_SPACE_SIZE) < 0) { - xen_host_pci_device_put(&s->real_device); - return -1; + rc = xen_host_pci_get_block(&s->real_device, 0, d->config, + PCI_CONFIG_SPACE_SIZE); + if (rc < 0) { + XEN_PT_ERR(d,"Could not read PCI_CONFIG space! (rc:%d)\n", rc); + goto err_out; } s->memory_listener = xen_pt_memory_listener; @@ -787,17 +788,17 @@ static int xen_pt_initfn(PCIDevice *d) xen_pt_register_regions(s, &cmd); /* reinitialize each config register to be emulated */ - if (xen_pt_config_init(s)) { + rc = xen_pt_config_init(s); + if (rc) { XEN_PT_ERR(d, "PCI Config space initialisation failed.\n"); - xen_host_pci_device_put(&s->real_device); - return -1; + goto err_out; } /* Bind interrupt */ rc = xen_host_pci_get_byte(&s->real_device, PCI_INTERRUPT_PIN, &scratch); if (rc) { XEN_PT_ERR(d, "Failed to read PCI_INTERRUPT_PIN! (rc:%d)\n", rc); - scratch = 0; + goto err_out; } if (!scratch) { XEN_PT_LOG(d, "no pin interrupt\n"); @@ -854,12 +855,14 @@ out: rc = xen_host_pci_get_word(&s->real_device, PCI_COMMAND, &val); if (rc) { XEN_PT_ERR(d, "Failed to read PCI_COMMAND! (rc: %d)\n", rc); + goto err_out; } else { val |= cmd; rc = xen_host_pci_set_word(&s->real_device, PCI_COMMAND, val); if (rc) { XEN_PT_ERR(d, "Failed to write PCI_COMMAND val=0x%x!(rc: %d)\n", val, rc); + goto err_out; } } } @@ -872,6 +875,11 @@ out: s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function); return 0; + +err_out: + xen_pt_destroy(d); + assert(rc); + return rc; } static void xen_pt_unregister_device(PCIDevice *d)