From patchwork Sun Jul 9 16:37:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9831829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 58C4760317 for ; Sun, 9 Jul 2017 16:40:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3381D22638 for ; Sun, 9 Jul 2017 16:40:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22CE926E46; Sun, 9 Jul 2017 16:40:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9B1E922638 for ; Sun, 9 Jul 2017 16:40:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUFDH-0004IJ-E8; Sun, 09 Jul 2017 16:37:39 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUFDG-0004ID-1v for xen-devel@lists.xenproject.org; Sun, 09 Jul 2017 16:37:38 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id C8/42-02181-1DB52695; Sun, 09 Jul 2017 16:37:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRWlGSWpSXmKPExsUSyFQ8RfdCdFK kwblmdYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePH1IqCg3wVs74eYWpgPMXdxcjFISRwjFFi VsNaFghnCaNE36ZPrF2MnBxsAnoSR2+sZAexRQQkJX53nWYGKWIWmMQosWLTE2aQhLBAlMSPq V/AGlgEVCX+zXgJFucVsJXo7W5mA7ElBOQldrVdZJ3AyLmAkWEVo0ZxalFZapGukaFeUlFmek ZJbmJmjq6hgbFebmpxcWJ6ak5iUrFecn7uJkagx+oZGBh3MPbs9TvEKMnBpCTKK9abECnEl5S fUpmRWJwRX1Sak1p8iFGGg0NJgvdAVFKkkGBRanpqRVpmDjB0YNISHDxKIrwnPiRGCvEWFyTm FmemQ6ROMepyvJrw/xuTEEtefl6qlDhvCcgMAZCijNI8uBGwML7EKCslzMvIwMAgxFOQWpSbW YIq/4pRnINRSZh3DsgUnsy8ErhNr4COYAI6gq0uAeSIkkSElFQDo+KJj04JuWYClmy6CTalvH ffbtm1Kv/Y+yyJxUtmWTC9X67A2eq+c7P7tTUtsnPM2Pdqa3Rbeb94q/IzsOH38QdOc832OU8 6dz7744oL8jPMfEO2SiZW3flR2PjwKvv1Y88bnbWW8B541agsvS70WYOYp+N8m6VTmn9bNkXf /jKzWDj9xJJ4ZyWW4oxEQy3mouJEAPxJlt9eAgAA X-Env-Sender: pm215@archaic.org.uk X-Msg-Ref: server-3.tower-31.messagelabs.com!1499618256!104605636!1 X-Originating-IP: [81.2.115.148] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55890 invoked from network); 9 Jul 2017 16:37:36 -0000 Received: from orth.archaic.org.uk (HELO orth.archaic.org.uk) (81.2.115.148) by server-3.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 9 Jul 2017 16:37:36 -0000 Received: from mnementh.archaic.org.uk ([81.2.115.146]) by orth.archaic.org.uk with esmtp (Exim 4.84_2) (envelope-from ) id 1dUFD0-0000lt-PF; Sun, 09 Jul 2017 17:37:22 +0100 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1dUFD0-00051m-Nn; Sun, 09 Jul 2017 17:37:22 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Sun, 9 Jul 2017 17:37:22 +0100 Message-Id: <20170709163722.19284-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.11.0 Cc: Anthony Perard , xen-devel@lists.xenproject.org, Stefano Stabellini , patches@linaro.org Subject: [Xen-devel] [PATCH] xen_pt_msi.c: Check for xen_host_pci_get_* failures in xen_pt_msix_init() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Check the return status of the xen_host_pci_get_* functions we call in xen_pt_msix_init(), and fail device init if the reads failed rather than ploughing ahead. (Spotted by Coverity: CID 777338.) Signed-off-by: Peter Maydell Reviewed-by: Stefano Stabellini --- Disclaimer: compile tested only! The only other Xen-related Coverity issue outstanding is that we don't check the return value of net_hub_id_for_client() in xen_config_dev_nic(), but that's too complicated for me to figure out what the right thing to do is (or if it's even a bug at all). --- hw/xen/xen_pt_msi.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/xen/xen_pt_msi.c b/hw/xen/xen_pt_msi.c index 62add0639f..ff9a79f5d2 100644 --- a/hw/xen/xen_pt_msi.c +++ b/hw/xen/xen_pt_msi.c @@ -535,7 +535,11 @@ int xen_pt_msix_init(XenPCIPassthroughState *s, uint32_t base) return -1; } - xen_host_pci_get_word(hd, base + PCI_MSIX_FLAGS, &control); + rc = xen_host_pci_get_word(hd, base + PCI_MSIX_FLAGS, &control); + if (rc) { + XEN_PT_ERR(d, "Failed to read PCI_MSIX_FLAGS field\n"); + return rc; + } total_entries = control & PCI_MSIX_FLAGS_QSIZE; total_entries += 1; @@ -554,7 +558,11 @@ int xen_pt_msix_init(XenPCIPassthroughState *s, uint32_t base) + XC_PAGE_SIZE - 1) & XC_PAGE_MASK); - xen_host_pci_get_long(hd, base + PCI_MSIX_TABLE, &table_off); + rc = xen_host_pci_get_long(hd, base + PCI_MSIX_TABLE, &table_off); + if (rc) { + XEN_PT_ERR(d, "Failed to read PCI_MSIX_TABLE field\n"); + goto error_out; + } bar_index = msix->bar_index = table_off & PCI_MSIX_FLAGS_BIRMASK; table_off = table_off & ~PCI_MSIX_FLAGS_BIRMASK; msix->table_base = s->real_device.io_regions[bar_index].base_addr;