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

[Xen-changelog] [xen master] xmalloc: stop using a magic '1' in alignment padding



commit 782a6b951a2317e1c3ecc81b6d94be09157fc363
Author:     Paul Durrant <paul.durrant@xxxxxxxxxx>
AuthorDate: Thu Jul 4 16:03:47 2019 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Jul 4 16:03:47 2019 +0200

    xmalloc: stop using a magic '1' in alignment padding
    
    Alignment padding inserts a pseudo block header in front of the allocation,
    sets its size field to the pad size and then ORs in 1, which is equivalent
    to marking it as a free block, so that xfree() can distinguish it from a
    real block header.
    
    This patch simply replaces the magic '1' with the defined 'FREE_BLOCK' to
    make it more obvious what's going on. Also, whilst in the neighbourhood,
    it removes a stray space after a cast.
    
    Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/common/xmalloc_tlsf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
index 2076953ac4..f585388dfa 100644
--- a/xen/common/xmalloc_tlsf.c
+++ b/xen/common/xmalloc_tlsf.c
@@ -595,7 +595,7 @@ void *_xmalloc(unsigned long size, unsigned long align)
         char *q = (char *)p + pad;
         struct bhdr *b = (struct bhdr *)(q - BHDR_OVERHEAD);
         ASSERT(q > (char *)p);
-        b->size = pad | 1;
+        b->size = pad | FREE_BLOCK;
         p = q;
     }
 
@@ -638,12 +638,12 @@ void xfree(void *p)
     }
 
     /* Strip alignment padding. */
-    b = (struct bhdr *)((char *) p - BHDR_OVERHEAD);
-    if ( b->size & 1 )
+    b = (struct bhdr *)((char *)p - BHDR_OVERHEAD);
+    if ( b->size & FREE_BLOCK )
     {
-        p = (char *)p - (b->size & ~1u);
+        p = (char *)p - (b->size & ~FREE_BLOCK);
         b = (struct bhdr *)((char *)p - BHDR_OVERHEAD);
-        ASSERT(!(b->size & 1));
+        ASSERT(!(b->size & FREE_BLOCK));
     }
 
     xmem_pool_free(p, xenpool);
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.