From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xenproject.org
Cc: Olaf Hering <olaf@aepfle.de>, Ian Jackson <iwj@xenproject.org>,
Wei Liu <wl@xen.org>
Subject: [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long
Date: Wed, 9 Dec 2020 16:54:49 +0100 [thread overview]
Message-ID: <20201209155452.28376-1-olaf@aepfle.de> (raw)
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)
next reply other threads:[~2020-12-09 15:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-09 15:54 Olaf Hering [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201209155452.28376-1-olaf@aepfle.de \
--to=olaf@aepfle.de \
--cc=iwj@xenproject.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.