From: Avi Kivity <[email protected]>

Move initialization after we're certain to succeed, so we don't leak
memory on failure.

Acked-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Avi Kivity <[email protected]>

diff --git a/hw/msix.c b/hw/msix.c
index 9663b17..162faa7 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -374,12 +374,6 @@ int msix_init(struct PCIDevice *dev, unsigned short 
nentries,
     if (nentries > MSIX_MAX_ENTRIES)
         return -EINVAL;
 
-#ifdef KVM_CAP_IRQCHIP
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        dev->msix_irq_entries = qemu_malloc(nentries *
-                                            sizeof *dev->msix_irq_entries);
-    }
-#endif
     dev->msix_mask_notifier_opaque =
         qemu_mallocz(nentries * sizeof *dev->msix_mask_notifier_opaque);
     dev->msix_mask_notifier = NULL;
@@ -401,6 +395,13 @@ int msix_init(struct PCIDevice *dev, unsigned short 
nentries,
     if (ret)
         goto err_config;
 
+#ifdef KVM_CAP_IRQCHIP
+    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
+        dev->msix_irq_entries = qemu_malloc(nentries *
+                                            sizeof *dev->msix_irq_entries);
+    }
+#endif
+
     dev->cap_present |= QEMU_PCI_CAP_MSIX;
     return 0;
 
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to