[PATCH 56/75] backports: Add devm_bitmap_zalloc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The carl9170 driver is using devm_bitmap_zalloc() now.

Signed-off-by: Hauke Mehrtens <hauke@xxxxxxxxxx>
---
 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 --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);
-- 
2.45.2





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux