From nobody Wed Nov 5 06:38:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499618311732577.4856203189341; Sun, 9 Jul 2017 09:38:31 -0700 (PDT) Received: from localhost ([::1]:36814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUFE5-0003iv-Ub for importer@patchew.org; Sun, 09 Jul 2017 12:38:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUFDH-0003S1-Cb for qemu-devel@nongnu.org; Sun, 09 Jul 2017 12:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUFDE-0002Kc-9A for qemu-devel@nongnu.org; Sun, 09 Jul 2017 12:37:39 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37488) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dUFDE-0002AF-1h for qemu-devel@nongnu.org; Sun, 09 Jul 2017 12:37:36 -0400 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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] xen_pt_msi.c: Check for xen_host_pci_get_* failures in xen_pt_msix_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , xen-devel@lists.xenproject.org, Stefano Stabellini , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; } =20 - xen_host_pci_get_word(hd, base + PCI_MSIX_FLAGS, &control); + rc =3D 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 =3D control & PCI_MSIX_FLAGS_QSIZE; total_entries +=3D 1; =20 @@ -554,7 +558,11 @@ int xen_pt_msix_init(XenPCIPassthroughState *s, uint32= _t base) + XC_PAGE_SIZE - 1) & XC_PAGE_MASK); =20 - xen_host_pci_get_long(hd, base + PCI_MSIX_TABLE, &table_off); + rc =3D 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 =3D msix->bar_index =3D table_off & PCI_MSIX_FLAGS_BIRMASK; table_off =3D table_off & ~PCI_MSIX_FLAGS_BIRMASK; msix->table_base =3D s->real_device.io_regions[bar_index].base_addr; --=20 2.11.0