[PATCH] thinko fix: move memset to after mmap failure check

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

 



By the time we've done a memset, it's too late to
check the pointer for MAP_FAILED value. Let's compare
to MAP_FAILED first.

Signed-off-by: Michael S. Tsikirn <mst@xxxxxxxxxx>
---

Noticed this when reading the code.
Makes sense, does it not?

 hw/device-assignment.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 1f0a1a7..0a5f850 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -1087,12 +1087,12 @@ static int assigned_dev_register_msix_mmio(AssignedDevice *dev)
     dev->msix_table_page = mmap(NULL, 0x1000,
                                 PROT_READ|PROT_WRITE,
                                 MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
-    memset(dev->msix_table_page, 0, 0x1000);
     if (dev->msix_table_page == MAP_FAILED) {
         fprintf(stderr, "fail allocate msix_table_page! %s\n",
                 strerror(errno));
         return -EFAULT;
     }
+    memset(dev->msix_table_page, 0, 0x1000);
     dev->mmio_index = cpu_register_io_memory(0,
                         msix_mmio_read, msix_mmio_write, dev);
     return 0;
-- 
1.6.0.6

--
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