From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
"Rafael J. Wysocki" <rafael@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <davidgow@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Hans de Goede <hdegoede@redhat.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
James Seo <james@equiv.tech>, Jason Baron <jbaron@akamai.com>,
Kees Cook <keescook@chromium.org>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Marco Elver <elver@google.com>, Mark Brown <broonie@kernel.org>,
Ming Lei <ming.lei@redhat.com>,
Petr Tesarik <petr.tesarik.ext@huawei.com>,
Rae Moar <rmoar@google.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Yury Norov <yury.norov@gmail.com>
Subject: [PATCH 1/2] lib/bitmap: move bitmap allocators for device to linux/device.h
Date: Sat, 7 Oct 2023 16:35:09 -0700 [thread overview]
Message-ID: <20231007233510.2097166-2-yury.norov@gmail.com> (raw)
In-Reply-To: <20231007233510.2097166-1-yury.norov@gmail.com>
The allocators are simple wrappers around bitmap_{alloc,free}().
So move them from bitmap to device sources.
Similarly to other device wrappers, turn them to static inlines
and place in header.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
include/linux/bitmap.h | 8 --------
include/linux/device.h | 30 ++++++++++++++++++++++++++++++
lib/bitmap.c | 33 ---------------------------------
3 files changed, 30 insertions(+), 41 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 03644237e1ef..ce8fcd8736f1 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -11,8 +11,6 @@
#include <linux/string.h>
#include <linux/types.h>
-struct device;
-
/*
* bitmaps provide bit arrays that consume one or more unsigned
* longs. The bitmap interface and available operations are listed
@@ -125,12 +123,6 @@ unsigned long *bitmap_alloc_node(unsigned int nbits, gfp_t flags, int node);
unsigned long *bitmap_zalloc_node(unsigned int nbits, gfp_t flags, int node);
void bitmap_free(const unsigned long *bitmap);
-/* Managed variants of the above. */
-unsigned long *devm_bitmap_alloc(struct device *dev,
- unsigned int nbits, gfp_t flags);
-unsigned long *devm_bitmap_zalloc(struct device *dev,
- unsigned int nbits, gfp_t flags);
-
/*
* lib/bitmap.c provides these functions:
*/
diff --git a/include/linux/device.h b/include/linux/device.h
index 56d93a1ffb7b..01b8161b283a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -435,6 +435,36 @@ struct device_dma_parameters {
unsigned long segment_boundary_mask;
};
+static inline void devm_bitmap_free(void *data)
+{
+ unsigned long *bitmap = data;
+
+ bitmap_free(bitmap);
+}
+
+static inline 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;
+}
+
+static inline unsigned long *devm_bitmap_zalloc(struct device *dev,
+ unsigned int nbits, gfp_t flags)
+{
+ return devm_bitmap_alloc(dev, nbits, flags | __GFP_ZERO);
+}
+
/**
* enum device_link_state - Device link states.
* @DL_STATE_NONE: The presence of the drivers is not being tracked.
diff --git a/lib/bitmap.c b/lib/bitmap.c
index ddb31015e38a..41f32fa3a80f 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -8,7 +8,6 @@
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/ctype.h>
-#include <linux/device.h>
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/kernel.h>
@@ -1415,38 +1414,6 @@ void bitmap_free(const unsigned long *bitmap)
}
EXPORT_SYMBOL(bitmap_free);
-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);
-
#if BITS_PER_LONG == 64
/**
* bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap
--
2.39.2
next prev parent reply other threads:[~2023-10-07 23:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-07 23:35 [PATCH 0/2] lib: unload lib/bitmap.c Yury Norov
2023-10-07 23:35 ` Yury Norov [this message]
2023-10-08 4:53 ` [PATCH 1/2] lib/bitmap: move bitmap allocators for device to linux/device.h Greg Kroah-Hartman
2023-10-08 15:39 ` Yury Norov
2023-10-08 16:31 ` Greg Kroah-Hartman
2023-10-07 23:35 ` [PATCH 2/2] lib/bitmap: split-out string-related operations to a separate files Yury Norov
2023-10-15 2:32 ` [PATCH 0/2] lib: unload lib/bitmap.c Yury Norov
2023-10-16 18:38 ` Greg Kroah-Hartman
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=20231007233510.2097166-2-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brendan.higgins@linux.dev \
--cc=broonie@kernel.org \
--cc=davidgow@google.com \
--cc=elver@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=james@equiv.tech \
--cc=jbaron@akamai.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=ming.lei@redhat.com \
--cc=petr.tesarik.ext@huawei.com \
--cc=rafael@kernel.org \
--cc=rmoar@google.com \
--cc=tglx@linutronix.de \
--cc=wangkefeng.wang@huawei.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome