All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jeffy Chen <jeffy.chen@rock-chips.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/3] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free()
Date: Fri, 1 Jun 2018 11:33:43 -0700	[thread overview]
Message-ID: <20180601183343.GA222005@dtor-ws> (raw)
In-Reply-To: <20180601083120.40352-1-andriy.shevchenko@linux.intel.com>

Hi Andy,

On Fri, Jun 01, 2018 at 11:31:18AM +0300, Andy Shevchenko wrote:
> 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>

This looks nice and I like how it simplifies drivers. How do we merge
this? 

> ---
>  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);

	retrun bitmap_alloc(nbits, flags | __GFP_ZERO);

?

> +}
> +
> +static inline void bitmap_free(const unsigned long *bitmap)
> +{
> +	kfree(bitmap);
> +}
> +
>  /*
>   * lib/bitmap.c provides these functions:
>   */
> -- 
> 2.17.0
> 

Thanks.

-- 
Dmitry

  parent reply	other threads:[~2018-06-01 18:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Dmitry Torokhov [this message]
2018-06-04  9:59   ` [PATCH v1 1/3] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Andy Shevchenko
2018-06-04 21:57     ` Dmitry Torokhov
2018-06-04 22:14       ` Dmitry Torokhov

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=20180601183343.GA222005@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jeffy.chen@rock-chips.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.