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

[xen staging] tools: allocate bitmaps in units of unsigned long



commit 8b90e311e0912b822621167621c515b41ea3d8e2
Author:     Olaf Hering <olaf@xxxxxxxxx>
AuthorDate: Wed Dec 9 16:54:49 2020 +0100
Commit:     Wei Liu <wl@xxxxxxx>
CommitDate: Tue Dec 15 16:23:14 2020 +0000

    tools: allocate bitmaps in units of unsigned long
    
    Allocate enough memory so that the returned pointer can be safely
    accessed as an array of unsigned long.
    
    The actual bitmap size in units of bytes, as returned by bitmap_size,
    remains unchanged.
    
    Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
    Acked-by: Wei Liu <wl@xxxxxxx>
---
 tools/libs/ctrl/xc_bitops.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
index 3d3a09772a..d6c5ea5138 100644
--- a/tools/libs/ctrl/xc_bitops.h
+++ b/tools/libs/ctrl/xc_bitops.h
@@ -21,7 +21,10 @@ static inline unsigned long bitmap_size(unsigned long 
nr_bits)
 
 static inline void *bitmap_alloc(unsigned long nr_bits)
 {
-    return calloc(1, bitmap_size(nr_bits));
+    unsigned long longs;
+
+    longs = (nr_bits + BITS_PER_LONG - 1) / BITS_PER_LONG;
+    return calloc(longs, sizeof(unsigned long));
 }
 
 static inline void bitmap_set(void *addr, unsigned long nr_bits)
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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