summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2010-07-08 08:58:32 -0600
committerMarcelo Tosatti <mtosatti@redhat.com>2010-07-12 15:12:43 -0300
commitdd09bf100b244a4af389eb5e427e1986836366e5 (patch)
tree8b3dd2a818cfdc97b190afcce4f8b4aec6fa1eaf /hw
parentabdb34211eebd964d097b55ee1a1ed05f8498477 (diff)
device-assignment: Better fd tracking
Commit 909bfdba fixed a hole with not closing resource file descriptors but we need to be more careful about tracking which are real fds, otherwise we might close fd 0, which doesn't work out so well for stdio. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Acked-by: Donald Dutile <ddutile@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/device-assignment.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 48ac73c98..de9470c60 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -694,6 +694,7 @@ again:
rp = dev->regions + r;
rp->valid = 0;
+ rp->resource_fd = -1;
size = end - start + 1;
flags &= IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH;
if (size == 0 || (flags & ~IORESOURCE_PREFETCH) == 0)
@@ -785,7 +786,9 @@ static void free_assigned_device(AssignedDevice *dev)
fprintf(stderr,
"Failed to unmap assigned device region: %s\n",
strerror(errno));
- close(pci_region->resource_fd);
+ if (pci_region->resource_fd >= 0) {
+ close(pci_region->resource_fd);
+ }
}
}
}
@@ -793,9 +796,8 @@ static void free_assigned_device(AssignedDevice *dev)
if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX)
assigned_dev_unregister_msix_mmio(dev);
- if (dev->real_device.config_fd) {
+ if (dev->real_device.config_fd >= 0) {
close(dev->real_device.config_fd);
- dev->real_device.config_fd = 0;
}
#ifdef KVM_CAP_IRQ_ROUTING
@@ -1415,7 +1417,7 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
if (!dev->host.seg && !dev->host.bus && !dev->host.dev && !dev->host.func) {
error_report("pci-assign: error: no host device specified");
- goto out;
+ return -1;
}
if (get_real_device(dev, dev->host.seg, dev->host.bus,