diff mbox series

[56/75] backports: Add devm_bitmap_zalloc()

Message ID 20240627234808.1253337-57-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
The carl9170 driver is using devm_bitmap_zalloc() now.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 backport/backport-include/linux/bitmap.h | 17 ++++++++++++
 backport/compat/backport-5.13.c          | 34 ++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
 create mode 100644 backport/backport-include/linux/bitmap.h
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 00000000..a09c5a68
--- /dev/null
+++ b/backport/backport-include/linux/bitmap.h
@@ -0,0 +1,17 @@ 
+#ifndef __BP_LINUX_BITMAP_H
+#define __BP_LINUX_BITMAP_H
+#include_next <linux/bitmap.h>
+
+#if LINUX_VERSION_IS_LESS(5,13,0)
+/* Managed variants of the above. */
+#define devm_bitmap_alloc LINUX_BACKPORT(devm_bitmap_alloc)
+unsigned long *devm_bitmap_alloc(struct device *dev,
+				 unsigned int nbits, gfp_t flags);
+
+#define devm_bitmap_zalloc LINUX_BACKPORT(devm_bitmap_zalloc)
+unsigned long *devm_bitmap_zalloc(struct device *dev,
+				  unsigned int nbits, gfp_t flags);
+
+#endif
+
+#endif /* __BP_LINUX_BITMAP_H */
diff --git a/backport/compat/backport-5.13.c b/backport/compat/backport-5.13.c
index c10b3321..8ec5865d 100644
--- a/backport/compat/backport-5.13.c
+++ b/backport/compat/backport-5.13.c
@@ -2,6 +2,8 @@ 
 
 #include <linux/export.h>
 #include <linux/interrupt.h>
+#include <linux/bitmap.h>
+#include <linux/device.h>
 
 #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT)
 /*
@@ -28,3 +30,35 @@  void tasklet_unlock_spin_wait(struct tasklet_struct *t)
 }
 EXPORT_SYMBOL_GPL(tasklet_unlock_spin_wait);
 #endif
+
+static void devm_bitmap_free(void *data)
+{
+	unsigned long *bitmap = data;
+
+	bitmap_free(bitmap);
+}
+
+unsigned long *devm_bitmap_alloc(struct device *dev,
+				 unsigned int nbits, gfp_t flags)
+{
+	unsigned long *bitmap;
+	int ret;
+
+	bitmap = bitmap_alloc(nbits, flags);
+	if (!bitmap)
+		return NULL;
+
+	ret = devm_add_action_or_reset(dev, devm_bitmap_free, bitmap);
+	if (ret)
+		return NULL;
+
+	return bitmap;
+}
+EXPORT_SYMBOL_GPL(devm_bitmap_alloc);
+
+unsigned long *devm_bitmap_zalloc(struct device *dev,
+				  unsigned int nbits, gfp_t flags)
+{
+	return devm_bitmap_alloc(dev, nbits, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL_GPL(devm_bitmap_zalloc);