All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long
@ 2020-12-09 15:54 Olaf Hering
  2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Olaf Hering @ 2020-12-09 15:54 UTC (permalink / raw)
  To: xen-devel; +Cc: Olaf Hering, Ian Jackson, Wei Liu

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>
---
 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)


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-12-15 16:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-09 15:54 [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Olaf Hering
2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
2020-12-15 16:20   ` Wei Liu
2020-12-09 15:54 ` [PATCH v1 3/3] tools: add API to work with sevaral bits at once Olaf Hering
2020-12-15 16:22   ` Wei Liu
2020-12-15 16:29     ` Olaf Hering
2020-12-15 16:30       ` Wei Liu
2020-12-15 16:11 ` [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.