LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1 1/3] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free()
@ 2018-06-01  8:31 Andy Shevchenko
  2018-06-01  8:31 ` [PATCH v1 2/3] Input: gpio-keys - Switch to bitmap_zalloc() Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Andy Shevchenko @ 2018-06-01  8:31 UTC (permalink / raw)
  To: Dmitry Torokhov, Jeffy Chen, linux-input, linux-kernel; +Cc: Andy Shevchenko

A lot of code become ugly because of open coding allocations for bitmaps.

Introduce three helpers to allow users be more clear of intention
and keep their code neat.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/bitmap.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 1ee46f492267..845822425393 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -6,6 +6,7 @@
 
 #include <linux/types.h>
 #include <linux/bitops.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/kernel.h>
 
@@ -104,6 +105,21 @@
  * contain all bit positions from 0 to 'bits' - 1.
  */
 
+static inline unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags)
+{
+	return kmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long), flags);
+}
+
+static inline unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags)
+{
+	return kcalloc(BITS_TO_LONGS(nbits), sizeof(unsigned long), flags);
+}
+
+static inline void bitmap_free(const unsigned long *bitmap)
+{
+	kfree(bitmap);
+}
+
 /*
  * lib/bitmap.c provides these functions:
  */
-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-06-04 22:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-01  8:31 [PATCH v1 1/3] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Andy Shevchenko
2018-06-01  8:31 ` [PATCH v1 2/3] Input: gpio-keys - Switch to bitmap_zalloc() Andy Shevchenko
2018-06-01 18:34   ` Dmitry Torokhov
2018-06-01  8:31 ` [PATCH v1 3/3] Input: evdev " Andy Shevchenko
2018-06-01 18:34   ` Dmitry Torokhov
2018-06-01 18:33 ` [PATCH v1 1/3] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Dmitry Torokhov
2018-06-04  9:59   ` Andy Shevchenko
2018-06-04 21:57     ` Dmitry Torokhov
2018-06-04 22:14       ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).