[PATCH 1/3] qemu-kvm: pci-assign: Clean up free_assigned_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>

The dev argument is never NULL for all free_assigned_device use cases.
So remove the check and one indention level.

Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 hw/device-assignment.c |   70 +++++++++++++++++++++++------------------------
 1 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 4997b6e..50a7485 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -801,52 +801,50 @@ static void free_dev_irq_entries(AssignedDevice *dev)
 
 static void free_assigned_device(AssignedDevice *dev)
 {
-    if (dev) {
-        int i;
-
-        for (i = 0; i < dev->real_device.region_number; i++) {
-            PCIRegion *pci_region = &dev->real_device.regions[i];
-            AssignedDevRegion *region = &dev->v_addrs[i];
+    int i;
 
-            if (!pci_region->valid)
-                continue;
+    for (i = 0; i < dev->real_device.region_number; i++) {
+        PCIRegion *pci_region = &dev->real_device.regions[i];
+        AssignedDevRegion *region = &dev->v_addrs[i];
 
-            if (pci_region->type & IORESOURCE_IO) {
-                if (pci_region->resource_fd < 0) {
-                    kvm_remove_ioperm_data(region->u.r_baseport,
-                                           region->r_size);
+        if (!pci_region->valid) {
+            continue;
+        }
+        if (pci_region->type & IORESOURCE_IO) {
+            if (pci_region->resource_fd < 0) {
+                kvm_remove_ioperm_data(region->u.r_baseport, region->r_size);
+            }
+        } else if (pci_region->type & IORESOURCE_MEM) {
+            if (region->u.r_virtbase) {
+                if (region->memory_index) {
+                    cpu_register_physical_memory(region->e_physbase,
+                                                 region->e_size,
+                                                 IO_MEM_UNASSIGNED);
+                    qemu_ram_unmap(region->memory_index);
                 }
-            } else if (pci_region->type & IORESOURCE_MEM) {
-                if (region->u.r_virtbase) {
-                    if (region->memory_index) {
-                        cpu_register_physical_memory(region->e_physbase,
-                                                     region->e_size,
-                                                     IO_MEM_UNASSIGNED);
-                        qemu_ram_unmap(region->memory_index);
-                    }
-                    if (munmap(region->u.r_virtbase,
-                               (pci_region->size + 0xFFF) & 0xFFFFF000))
-                        fprintf(stderr,
-				"Failed to unmap assigned device region: %s\n",
-				strerror(errno));
+                if (munmap(region->u.r_virtbase,
+                           (pci_region->size + 0xFFF) & 0xFFFFF000)) {
+                    fprintf(stderr,
+                            "Failed to unmap assigned device region: %s\n",
+                            strerror(errno));
                 }
             }
-            if (pci_region->resource_fd >= 0) {
-                close(pci_region->resource_fd);
-            }
         }
-
-        if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX)
-            assigned_dev_unregister_msix_mmio(dev);
-
-        if (dev->real_device.config_fd >= 0) {
-            close(dev->real_device.config_fd);
+        if (pci_region->resource_fd >= 0) {
+            close(pci_region->resource_fd);
         }
+    }
+
+    if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {
+        assigned_dev_unregister_msix_mmio(dev);
+    }
+    if (dev->real_device.config_fd >= 0) {
+        close(dev->real_device.config_fd);
+    }
 
 #ifdef KVM_CAP_IRQ_ROUTING
-        free_dev_irq_entries(dev);
+    free_dev_irq_entries(dev);
 #endif
-    }
 }
 
 static uint32_t calc_assigned_dev_id(uint16_t seg, uint8_t bus, uint8_t devfn)
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux