diff mbox series

[66/75] backports Add bitmap_alloc and bitmap_alloc

Message ID 20240627234808.1253337-67-hauke@hauke-m.de (mailing list archive)
State New, archived
Headers show
Series backports: Update to kernel 6.1.95 | expand

Commit Message

Hauke Mehrtens June 27, 2024, 11:47 p.m. UTC
These functions were added in kernel 4.19 and are used by mac80211 and
some drivers now.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 backport/backport-include/linux/bitmap.h | 11 +++++++++++
 backport/compat/Makefile                 |  1 +
 backport/compat/backport-4.19.c          | 21 +++++++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 backport/compat/backport-4.19.c
diff mbox series

Patch

diff --git a/backport/backport-include/linux/bitmap.h b/backport/backport-include/linux/bitmap.h
index a09c5a68..f352b57a 100644
--- a/backport/backport-include/linux/bitmap.h
+++ b/backport/backport-include/linux/bitmap.h
@@ -2,6 +2,17 @@ 
 #define __BP_LINUX_BITMAP_H
 #include_next <linux/bitmap.h>
 
+#if LINUX_VERSION_IS_LESS(4,19,0)
+#define bitmap_alloc LINUX_BACKPORT(bitmap_alloc)
+unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags);
+
+#define bitmap_zalloc LINUX_BACKPORT(bitmap_zalloc)
+unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags);
+
+#define bitmap_free LINUX_BACKPORT(bitmap_free)
+void bitmap_free(const unsigned long *bitmap);
+#endif
+
 #if LINUX_VERSION_IS_LESS(5,13,0)
 /* Managed variants of the above. */
 #define devm_bitmap_alloc LINUX_BACKPORT(devm_bitmap_alloc)
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index 698f14f5..0e48ca01 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -8,6 +8,7 @@  compat-y += main.o
 
 # Kernel backport compatibility code
 compat-$(CPTCFG_KERNEL_4_18) += backport-4.18.o
+compat-$(CPTCFG_KERNEL_4_19) += backport-4.19.o
 compat-$(CPTCFG_KERNEL_5_2) += backport-5.2.o backport-genetlink.o
 compat-$(CPTCFG_KERNEL_5_3) += backport-5.3.o
 compat-$(CPTCFG_KERNEL_5_5) += backport-5.5.o
diff --git a/backport/compat/backport-4.19.c b/backport/compat/backport-4.19.c
new file mode 100644
index 00000000..4dd00101
--- /dev/null
+++ b/backport/compat/backport-4.19.c
@@ -0,0 +1,21 @@ 
+#include <linux/bitmap.h>
+#include <linux/slab.h>
+
+unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags)
+{
+	return kmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long),
+			     flags);
+}
+EXPORT_SYMBOL_GPL(bitmap_alloc);
+
+unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags)
+{
+	return bitmap_alloc(nbits, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL_GPL(bitmap_zalloc);
+
+void bitmap_free(const unsigned long *bitmap)
+{
+	kfree(bitmap);
+}
+EXPORT_SYMBOL_GPL(bitmap_free);