tools: allocate bitmaps in units of unsigned long
authorOlaf Hering <olaf@aepfle.de>
Wed, 9 Dec 2020 15:54:49 +0000 (16:54 +0100)
committerWei Liu <wl@xen.org>
Tue, 15 Dec 2020 16:23:14 +0000 (16:23 +0000)
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@aepfle.de>
Acked-by: Wei Liu <wl@xen.org>
tools/libs/ctrl/xc_bitops.h

index 3d3a09772a863a8d5e4ba05ea46ec417e546010a..d6c5ea513852a6402fb0ea6d28a6ef27c904d010 100644 (file)
@@ -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)