提交 d7ab9021 编写于 作者: B Bartosz Golaszewski 提交者: Zheng Zengkai

lib: bitmap: provide devm_bitmap_alloc() and devm_bitmap_zalloc()

stable inclusion
from stable-v5.10.137
commit 26a10aef28d9e9bfaf975b390224009af6b10767
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60PLB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=26a10aef28d9e9bfaf975b390224009af6b10767

--------------------------------

[ Upstream commit e829c2e4 ]

Provide managed variants of bitmap_alloc() and bitmap_zalloc().
Signed-off-by: NBartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 e94bb1bd
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/types.h> #include <linux/types.h>
struct device;
/* /*
* bitmaps provide bit arrays that consume one or more unsigned * bitmaps provide bit arrays that consume one or more unsigned
* longs. The bitmap interface and available operations are listed * longs. The bitmap interface and available operations are listed
...@@ -122,6 +124,12 @@ extern unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags); ...@@ -122,6 +124,12 @@ extern unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags);
extern unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags); extern unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags);
extern void bitmap_free(const unsigned long *bitmap); extern 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: * lib/bitmap.c provides these functions:
*/ */
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/bug.h> #include <linux/bug.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/device.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -1263,6 +1264,38 @@ void bitmap_free(const unsigned long *bitmap) ...@@ -1263,6 +1264,38 @@ void bitmap_free(const unsigned long *bitmap)
} }
EXPORT_SYMBOL(bitmap_free); 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 #if BITS_PER_LONG == 64
/** /**
* bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册