summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2022-11-07 15:45:21 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-11-08 11:05:44 +0100
commitd87cb6746b2f6ae2409be78e83b10935d31405b0 (patch)
treead1179326446a364770be36bc28bb4a973fe4a19
parent731f070ca82d87352a865b125c595e5b507e2562 (diff)
downloadbarebox-d87cb6746b2f6ae2409be78e83b10935d31405b0.tar.gz
barebox-d87cb6746b2f6ae2409be78e83b10935d31405b0.tar.xz
bitmap: Implement bitmap_*zalloc()
Implement functions for allocating a bitmap. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20221107144524.489471-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/linux/bitmap.h7
-rw-r--r--lib/bitmap.c10
2 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index adaf5428fe..7d06fac68d 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -81,6 +81,13 @@
*/
/*
+ * Allocation and deallocation of bitmap.
+ * Provided in lib/bitmap.c to avoid circular dependency.
+ */
+unsigned long *bitmap_zalloc(unsigned int nbits);
+unsigned long *bitmap_xzalloc(unsigned int nbits);
+
+/*
* lib/bitmap.c provides these functions:
*/
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 5be6651941..dfc0f06b13 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -837,3 +837,13 @@ void bitmap_copy_le(void *dst, const unsigned long *src, int nbits)
}
}
EXPORT_SYMBOL(bitmap_copy_le);
+
+unsigned long *bitmap_zalloc(unsigned int nbits)
+{
+ return calloc(BITS_TO_LONGS(nbits), sizeof(unsigned long));
+}
+
+unsigned long *bitmap_xzalloc(unsigned int nbits)
+{
+ return xzalloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long));
+}