domain_page: handle NULL within unmap_domain_page() itself
authorHongyan Xia <hongyxia@amazon.com>
Wed, 13 May 2020 15:43:33 +0000 (16:43 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 15 May 2020 18:35:09 +0000 (19:35 +0100)
The macro version UNMAP_DOMAIN_PAGE() does both NULL checking and
variable clearing. Move NULL checking into the function itself so that
the semantics is consistent with other similar constructs like XFREE().
This also eases the use unmap_domain_page() in error handling paths,
where we only care about NULL checking but not about variable clearing.

Signed-off-by: Hongyan Xia <hongyxia@amazon.com>
Reviewed-by: Wei Liu <wl@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/arch/arm/mm.c
xen/arch/x86/domain_page.c
xen/include/xen/domain_page.h

index 727107eefaadeb7fa7c82b63d047bb37e7c4298c..1b14f4934570597e7d7b940d53f6de62004b946b 100644 (file)
@@ -498,6 +498,9 @@ void unmap_domain_page(const void *va)
     lpae_t *map = this_cpu(xen_dommap);
     int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
 
+    if ( !va )
+        return;
+
     local_irq_save(flags);
 
     ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
index dd32712d2fbeaa3fdc073b3a19a065d86dbf6c1d..b03728e18e1ef1ac279772d544a49e81c355612f 100644 (file)
@@ -181,7 +181,7 @@ void unmap_domain_page(const void *ptr)
     unsigned long va = (unsigned long)ptr, mfn, flags;
     struct vcpu_maphash_entry *hashent;
 
-    if ( va >= DIRECTMAP_VIRT_START )
+    if ( !va || va >= DIRECTMAP_VIRT_START )
         return;
 
     ASSERT(va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END);
index ab2be7b7191c5cded20739631cb37d3c6c3f9911..a182d33b670180870aba3ae37bfcc94d1638d9ce 100644 (file)
@@ -73,11 +73,8 @@ static inline void unmap_domain_page_global(const void *va) {};
 #endif /* !CONFIG_DOMAIN_PAGE */
 
 #define UNMAP_DOMAIN_PAGE(p) do {   \
-    if ( p )                        \
-    {                               \
-        unmap_domain_page(p);       \
-        (p) = NULL;                 \
-    }                               \
+    unmap_domain_page(p);           \
+    (p) = NULL;                     \
 } while ( false )
 
 #endif /* __XEN_DOMAIN_PAGE_H__ */