mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/4] bitmap: Implement bitmap_*zalloc()
Date: Mon,  7 Nov 2022 15:45:21 +0100	[thread overview]
Message-ID: <20221107144524.489471-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20221107144524.489471-1-s.hauer@pengutronix.de>

Implement functions for allocating a bitmap.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/linux/bitmap.h |  7 +++++++
 lib/bitmap.c           | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index adaf5428fe..7d06fac68d 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -80,6 +80,13 @@
  * contain all bit positions from 0 to 'bits' - 1.
  */
 
+/*
+ * Allocation and deallocation of bitmap.
+ * Provided in lib/bitmap.c to avoid circular dependency.
+ */
+unsigned long *bitmap_zalloc(unsigned int nbits);
+unsigned long *bitmap_xzalloc(unsigned int nbits);
+
 /*
  * lib/bitmap.c provides these functions:
  */
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 5be6651941..dfc0f06b13 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -837,3 +837,13 @@ void bitmap_copy_le(void *dst, const unsigned long *src, int nbits)
 	}
 }
 EXPORT_SYMBOL(bitmap_copy_le);
+
+unsigned long *bitmap_zalloc(unsigned int nbits)
+{
+	return calloc(BITS_TO_LONGS(nbits), sizeof(unsigned long));
+}
+
+unsigned long *bitmap_xzalloc(unsigned int nbits)
+{
+	return xzalloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long));
+}
-- 
2.30.2




  reply	other threads:[~2022-11-07 15:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 14:45 [PATCH 0/4] gpio: Add gpio latch driver Sascha Hauer
2022-11-07 14:45 ` Sascha Hauer [this message]
2022-11-07 14:45 ` [PATCH 2/4] bitops: include linux/types.h Sascha Hauer
2022-11-07 14:45 ` [PATCH 3/4] bitops: implement assign_bit() Sascha Hauer
2022-11-07 14:45 ` [PATCH 4/4] gpio: Add gpio latch driver Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221107144524.489471-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 1/4] bitmap: Implement bitmap_*zalloc()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox