From patchwork Fri Jun 1 08:31:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 10442771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 900DE602BC for ; Fri, 1 Jun 2018 08:32:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EFB828D1B for ; Fri, 1 Jun 2018 08:32:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73A6B28D2D; Fri, 1 Jun 2018 08:32:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 185DB28D1B for ; Fri, 1 Jun 2018 08:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751010AbeFAIb2 (ORCPT ); Fri, 1 Jun 2018 04:31:28 -0400 Received: from mga11.intel.com ([192.55.52.93]:39795 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750968AbeFAIbY (ORCPT ); Fri, 1 Jun 2018 04:31:24 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Jun 2018 01:31:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,465,1520924400"; d="scan'208";a="233516141" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 01 Jun 2018 01:31:21 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id B2F4A10B; Fri, 1 Jun 2018 11:31:20 +0300 (EEST) From: Andy Shevchenko To: Dmitry Torokhov , Jeffy Chen , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v1 1/3] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Date: Fri, 1 Jun 2018 11:31:18 +0300 Message-Id: <20180601083120.40352-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.17.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include +#include #include #include @@ -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); +} + +static inline void bitmap_free(const unsigned long *bitmap) +{ + kfree(bitmap); +} + /* * lib/bitmap.c provides these functions: */