diff mbox

[stable-0.15,4/6] pci-assign: Harden I/O port test

Message ID 1349806133-1916-5-git-send-email-afaerber@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Andreas Färber Oct. 9, 2012, 6:08 p.m. UTC
From: Alex Williamson <alex.williamson@redhat.com>

Markus Armbruster points out that we're missing a < 0 check
from pread while trying to probe for pci-sysfs io-port
resource support.  We don't expect a short read, but we
should harden the test to abort if we get one so we're not
potentially looking at a stale errno.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 1d1c8a498b7ce5c5636f1014f7ad18aa4e1acc0a)

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/device-assignment.c |    5 +++--
 1 Datei geändert, 3 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
diff mbox

Patch

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index c4c2535..d586ce4 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -618,8 +618,9 @@  static int assigned_dev_register_regions(PCIRegion *io_regions,
              * kernels return EIO.  New kernels only allow 1/2/4 byte reads
              * so should return EINVAL for a 3 byte read */
             ret = pread(pci_dev->v_addrs[i].region->resource_fd, &val, 3, 0);
-            if (ret == 3) {
-                fprintf(stderr, "I/O port resource supports 3 byte read?!\n");
+            if (ret >= 0) {
+                fprintf(stderr, "Unexpected return from I/O port read: %d\n",
+                        ret);
                 abort();
             } else if (errno != EINVAL) {
                 fprintf(stderr, "Using raw in/out ioport access (sysfs - %s)\n",