[PATCH 1/4] bitmap: Implement bitmap_*zalloc()

Sascha Hauer s.hauer at pengutronix.de
Mon Nov 7 06:45:21 PST 2022


Implement functions for allocating a bitmap.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/linux/bitmap.h |  7 +++++++
 lib/bitmap.c           | 10 ++++++++++
 2 files changed, 17 insertions(+)

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
@@ -80,6 +80,13 @@
  * contain all bit positions from 0 to 'bits' - 1.
  */
 
+/*
+ * 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));
+}
-- 
2.30.2




More information about the barebox mailing list