]> xenbits.xensource.com Git - xen.git/commitdiff
x86/vpci: validate data first in register_vpci_mmcfg_handler
authorWei Liu <wei.liu2@citrix.com>
Tue, 27 Mar 2018 11:04:20 +0000 (12:04 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 27 Mar 2018 15:29:46 +0000 (16:29 +0100)
Avoid the need to deallocate memory when the data is invalid. It has
the benefit to not fragment memory in Xen.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/io.c

index 556810c12627174cbd08ec543f9e2f8dfe0bb4d7..9af5e3fee6320346f6381b622c07971668a9f90e 100644 (file)
@@ -511,18 +511,16 @@ int register_vpci_mmcfg_handler(struct domain *d, paddr_t addr,
                                 unsigned int start_bus, unsigned int end_bus,
                                 unsigned int seg)
 {
-    struct hvm_mmcfg *mmcfg, *new = xmalloc(struct hvm_mmcfg);
+    struct hvm_mmcfg *mmcfg, *new;
 
     ASSERT(is_hardware_domain(d));
 
-    if ( !new )
-        return -ENOMEM;
-
     if ( start_bus > end_bus )
-    {
-        xfree(new);
         return -EINVAL;
-    }
+
+    new = xmalloc(struct hvm_mmcfg);
+    if ( !new )
+        return -ENOMEM;
 
     new->addr = addr + (start_bus << 20);
     new->start_bus = start_bus;