diff mbox series

[2/3] backports: add bitmap_zalloc/_free

Message ID 20240524201112.a746aafc99cc.I931412aa547e6b26a87de1b90f60fe6403073ef6@changeid (mailing list archive)
State New, archived
Headers show
Series [1/3] backports: add BITS_TO_BYTES() | expand

Commit Message

Johannes Berg May 24, 2024, 6:11 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 backport/backport-include/linux/bitmap.h | 10 ++++++++++
 backport/compat/Makefile                 |  1 +
 backport/compat/backport-4.19.c          | 15 +++++++++++++++
 3 files changed, 26 insertions(+)
 create mode 100644 backport/backport-include/linux/bitmap.h
 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
new file mode 100644
index 000000000000..d7a0260b6001
--- /dev/null
+++ b/backport/backport-include/linux/bitmap.h
@@ -0,0 +1,10 @@ 
+#ifndef __BP_LINUX_BITMAP_H
+#define __BP_LINUX_BITMAP_H
+#include_next <linux/bitmap.h>
+
+#if LINUX_VERSION_IS_LESS(4,19,0)
+unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags);
+void bitmap_free(const unsigned long *bitmap);
+#endif /* < 4.19 */
+
+#endif /* __BP_LINUX_BITMAP_H */
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index bb6fb57edc7e..29a9b3d8faa3 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 000000000000..2ea396757ed8
--- /dev/null
+++ b/backport/compat/backport-4.19.c
@@ -0,0 +1,15 @@ 
+#include <linux/bitmap.h>
+#include <linux/slab.h>
+
+unsigned long *
+bitmap_zalloc(unsigned int nbits, gfp_t flags)
+{
+	return kzalloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long), flags);
+}
+EXPORT_SYMBOL(bitmap_zalloc);
+
+void bitmap_free(const unsigned long *bitmap)
+{
+	kfree(bitmap);
+}
+EXPORT_SYMBOL(bitmap_free);