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: 107237 Delivered-To: patches@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2455278qge; Sun, 9 Jul 2017 09:37:29 -0700 (PDT) X-Received: by 10.28.66.22 with SMTP id p22mr4612667wma.56.1499618249153; Sun, 09 Jul 2017 09:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499618249; cv=none; d=google.com; s=arc-20160816; b=gQmzN0J6hBYsZM7USbIe90csRqt9LcG7nQa5UgcEa+GK7bixzisYNwcUWzwkIpF5bl Wl7TggE4CAT8Aha6xy7SrPYNegMheoGCHhXTnU9etisTp2DUEukdAu6dIijcCug5FpH1 YTba2q3F2qtzw/WVE0TtkEtfiap4NlOZH+CxhrNGj3fNUYCUYId0eqCPhWrupv4tjob2 5/o4WO3SE9VYwpTdkc67I0TrlorHT0TDPrGkJZrrS6D5yimFpOfPTWcXdDR/HAJlOBPW M/qTNvqMb6G4XJ03/4kuww65/RloahYXgETFb7NSdA+HbzNCZSKIw9o97EBe+QK7d6Bx Prcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=JzQRFN9XOqx9ufdW0xMcdXS4e4EnHdjSLS2LYKeS74U=; b=yH4thN5rrFwqYq/fklZQJS8Th5zR+xtUIHZs51QbZSnklHuL7SvhTdJEMDWq82RTkq X/69kS/Xe4PjWhrLehiSXC9CMYaLwJhiCAEN8KwlMBkdPaofQRFbHoKT3XHm5rfXkggw AJCn+l2xwfeXUIIrNJ9Katvw7WUnqfbuRlD8QS+1SyMjDw13BHE3VDpab+FX+p21II5N w+aJRMAXaf5RFglMfqdzbutzQ9fbpsFkI6UvfobV1o1hq4dK7vdPvr49jOBljph53Kjm yROc3Gxd3oen6VDkbcCIuYA/J1FbjwWUBld2dvODmQRdjMLafKIKFuHrke4jRrPa6Dn+ Ap3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id q11si5984405wrd.374.2017.07.09.09.37.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2017 09:37:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org, Stefano Stabellini , Anthony Perard , xen-devel@lists.xenproject.org Subject: [PATCH] xen_pt_msi.c: Check for xen_host_pci_get_* failures in xen_pt_msix_init() 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 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 --- 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(-) -- 2.11.0 Reviewed-by: Stefano Stabellini 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;