From patchwork Tue Jul 18 22:22:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 108247 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp6516975qge; Tue, 18 Jul 2017 15:24:07 -0700 (PDT) X-Received: by 10.36.184.196 with SMTP id m187mr4525684ite.18.1500416647206; Tue, 18 Jul 2017 15:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500416647; cv=none; d=google.com; s=arc-20160816; b=d7Za3GW5UVxz+lI8EclGuv0KarN5a6gNwb9l/V3q9aeb6X3K+sNgfP2pq5pfwKScsV gcuSX1+W/RWVGTdPHs/n90GE4kwdGi0lFrMg7WTk0tvaIRadZlia+USHlonjAJ9cbmuc xyY9hM4HZlinp+KPjpmF9QNMEng56jjAZZmp0DkP0VZqYrJZctC/I16MtJOy9RDRoAID ue0Zirmf94UWo6wxQMXRQv5RZTmEBfYis2ShfjNk1SPar5aOmNSs/cxANQVQHRKa/eBL viPKPRi7G1ZbntZu38HXrUfTzWLgd8BCu4K9bDKxu+/Xzmu30pUYnYd3oqaKC3P2qLdJ s3ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dmarc-filter:arc-authentication-results; bh=mo7oFQE/hR4IzT7M6X0SMJyTwj/OMNTnjcizimjpoYU=; b=nWH/KzBI0HbAvlOHZAEtVvzaGRZNisFCGAWkHGba3LOMguvMmqdw6mfhGZxeINg3Oy 1owiMNaaIJMrEUSSGfydHjxiP8EW5Tgm303fc2hx24l9rU/JdevLNiHwfxQ5lHF8keLI vsDo9fo2auy7eqGisdIvAY6i7JhCJ9A3a4zl2Leq4yNAbCpCb8bFrQj7DNccywacalDM mQHYs2ho40MGjvxKzmFXs8OzimdR96bYMCaEtSTU85pPRh9kylP6Gaa04s00JeWVfiqe fxXHs7kSxgVvkr5lZNrIzW/DmJYlm9T2Vu+TEQ+omC64Y75HwYzwDQafz2JcZAU1kYpI Kh3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g24si3423187ioi.72.2017.07.18.15.24.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 15:24:07 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXatE-0006yx-Pd; Tue, 18 Jul 2017 22:22:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXatD-0006yi-V3 for xen-devel@lists.xenproject.org; Tue, 18 Jul 2017 22:22:48 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 15/01-03582-73A8E695; Tue, 18 Jul 2017 22:22:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVybKJssq5ZV16 kwd7pWhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b3g6wFO3gr9vTtZ21gfMrVxcjFISSwjkni 1IFbrF2MnBwsAg4SN15vZ+pi5OBgFIiRePDDGiTMKBAmMfnyErASNgFDib9PNrGB2CJA9oOty 8HizAKtjBKHH3uB2MICaRI/Fl5ghxipKrFo+zRGEJtXwE1i2qR7TCC2hICcxMljk8F6OQXcJU 4te8UMcU87o8Shw19ZJjDyLmBkWMWoUZxaVJZapGtoppdUlJmeUZKbmJmja2hgppebWlycmJ6 ak5hUrJecn7uJERgMDECwg/H+xoBDjJIcTEqivFuV8yKF+JLyUyozEosz4otKc1KLDzHKcHAo SfDmdwLlBItS01Mr0jJzgGEJk5bg4FES4d3ZAZTmLS5IzC3OTIdInWLU5Xg14f83JiGWvPy8V ClxXl2QGQIgRRmleXAjYDFyiVFWSpiXEegoIZ6C1KLczBJU+VeM4hyMSsK8LSCreDLzSuA2vQ I6ggnoCGHfHJAjShIRUlINjAf3JSrOmJT5OkBO6I3L/JmJU+5ektoj8zVzX7S4sv7+UM1Nv4N q67/OmbBzlhd3UuynlOXiU8x21eX+ZJ9wTcdx64vMpt0Jc/+5mD5mWWNfqPfO6NOO5HgXpSKt tiXhMerLXoqxbfj2LfjSIZ93De8mOf7i2J+29u8tncsLJk+bvqWsqbD98kclluKMREMt5qLiR ABBRHVajAIAAA== X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-13.tower-21.messagelabs.com!1500416565!68009021!1 X-Originating-IP: [198.145.29.99] 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 50299 invoked from network); 18 Jul 2017 22:22:46 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-13.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 18 Jul 2017 22:22:46 -0000 Received: from localhost.localdomain (162-198-228-33.lightspeed.wlfrct.sbcglobal.net [162.198.228.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9E0A622BE9; Tue, 18 Jul 2017 22:22:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E0A622BE9 From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 18 Jul 2017 15:22:37 -0700 Message-Id: <1500416562-27337-2-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500416562-27337-1-git-send-email-sstabellini@kernel.org> References: <1500416562-27337-1-git-send-email-sstabellini@kernel.org> Cc: anthony.perard@citrix.com, xen-devel@lists.xenproject.org, sstabellini@kernel.org, qemu-devel@nongnu.org, stefanha@redhat.com Subject: [Xen-devel] [PULL for-2.10 2/7] 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" From: Peter Maydell 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 Signed-off-by: Stefano Stabellini --- 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 62add06..ff9a79f 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;