]> xenbits.xensource.com Git - xen.git/commitdiff
xen: Swap order of actions in the FREE*() macros
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 2 Feb 2024 00:39:42 +0000 (00:39 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 12 Mar 2024 16:22:44 +0000 (16:22 +0000)
Wherever possible, it is a good idea to NULL out the visible reference to an
object prior to freeing it.  The FREE*() macros already collect together both
parts, making it easy to adjust.

This has a marginal code generation improvement, as some of the calls to the
free() function can be tailcall optimised.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
(cherry picked from commit c4f427ec879e7c0df6d44d02561e8bee838a293e)

xen/include/xen/mm.h
xen/include/xen/xmalloc.h

index 3f5c296138cf4179a6a56e9999e5c77d94de0d42..c0b77d563d80b87e96e34b2156ef8b8d49f94593 100644 (file)
@@ -80,8 +80,9 @@ bool scrub_free_pages(void);
 
 /* Free an allocation, and zero the pointer to it. */
 #define FREE_XENHEAP_PAGES(p, o) do { \
-    free_xenheap_pages(p, o);         \
+    void *_ptr_ = (p);                \
     (p) = NULL;                       \
+    free_xenheap_pages(_ptr_, o);     \
 } while ( false )
 #define FREE_XENHEAP_PAGE(p) FREE_XENHEAP_PAGES(p, 0)
 
index 16979a117c6af3044d656b2f8f9dd625885da578..d857298011c11b3445da0f7b4e22faf60bc942c5 100644 (file)
 extern void xfree(void *);
 
 /* Free an allocation, and zero the pointer to it. */
-#define XFREE(p) do { \
-    xfree(p);         \
-    (p) = NULL;       \
+#define XFREE(p) do {                       \
+    void *_ptr_ = (p);                      \
+    (p) = NULL;                             \
+    xfree(_ptr_);                           \
 } while ( false )
 
 /* Underlying functions */