[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YEDaI/G+Qb9Q1dxR@smile.fi.intel.com>
Date: Thu, 4 Mar 2021 15:01:23 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Bartosz Golaszewski <brgl@...ev.pl>
Cc: Joel Becker <jlbec@...lplan.org>, Christoph Hellwig <hch@....de>,
Shuah Khan <shuah@...nel.org>,
Linus Walleij <linus.walleij@...aro.org>,
Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Kent Gibson <warthog618@...il.com>,
Jonathan Corbet <corbet@....net>, linux-gpio@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: Re: [PATCH v2 07/12] lib: bitmap: provide devm_bitmap_alloc() and
devm_bitmap_zalloc()
On Thu, Mar 04, 2021 at 11:24:47AM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@...libre.com>
>
> Provide managed variants of bitmap_alloc() and bitmap_zalloc().
Reviewed-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
A few nit-picks below.
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@...libre.com>
> ---
> include/linux/bitmap.h | 10 ++++++++++
> lib/bitmap.c | 33 +++++++++++++++++++++++++++++++++
> 2 files changed, 43 insertions(+)
>
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> index 3282db97e06c..e41c622db1b8 100644
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -9,6 +9,8 @@
> #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
> @@ -122,6 +124,14 @@ unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags);
> unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags);
> void bitmap_free(const unsigned long *bitmap);
> +/*
> + * Managed variants of the above.
> + */
One line?
> +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);
Both can be oneliners.
> /*
> * lib/bitmap.c provides these functions:
> */
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index 78f70d9007ad..b4fd7fd084c6 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -8,6 +8,7 @@
> #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>
> @@ -1263,6 +1264,38 @@ 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)
One line?
> +{
> + 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(devm_bitmap_alloc);
> +unsigned long *devm_bitmap_zalloc(struct device *dev,
> + unsigned int nbits, gfp_t flags)
One line?
> +{
> + return devm_bitmap_alloc(dev, nbits, flags | __GFP_ZERO);
> +}
> +EXPORT_SYMBOL(devm_bitmap_zalloc);
> +
> #if BITS_PER_LONG == 64
> /**
> * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap
> --
> 2.29.1
>
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists