From 4c12123672bade7f8a1547a567cb06a2c7b9e29b Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Tue, 24 Jan 2012 15:45:34 +0100 Subject: [PATCH 4/5] pci-assign: Harden I/O port test RH-Author: Alex Williamson Message-id: <20120124154534.27090.98710.stgit@bling.home> Patchwork-id: 36789 O-Subject: [PATCH 4/4] pci-assign: Harden I/O port test Bugzilla: 754565 RH-Acked-by: Laszlo Ersek RH-Acked-by: Markus Armbruster RH-Acked-by: Don Dutile Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=754565 Upstream commit: 1d1c8a498b7ce5c5636f1014f7ad18aa4e1acc0a 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 Signed-off-by: Avi Kivity --- hw/device-assignment.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) Signed-off-by: Michal Novotny --- hw/device-assignment.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 99c5419..053b053 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -636,8 +636,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", -- 1.7.7.5