Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3909090imm; Mon, 18 Jun 2018 06:13:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLKjd2n3dE3tYvCLqi0J0VhNzW3IQGKasAY/0aGmNdTE5IBjRplOWC/dswXYolUrGnz7yH6 X-Received: by 2002:a63:5f0c:: with SMTP id t12-v6mr10726828pgb.95.1529327610569; Mon, 18 Jun 2018 06:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529327610; cv=none; d=google.com; s=arc-20160816; b=AC3GQ3E8RKn62EItu/7J39Q+Bi0E87sme6jRvzEqT1IiEcQr2520PY7DBpYmWtEpCo WsYyRi+8YG05v2YXvHZDtLKo7yerh1uyHFQIIJ8xR59GPTEr0UH4JQHr9J5xXnpiigxz 7ATbzZX2COJUHqbySzdRLLyRpERvIyT1AZS3krZTqb1ggRrR9Jv0sWcsUt6cgoP2NZoL L0AvNlVsZKygAFX108LulyJwr0Rjo82BaykvVgEGlScPO7Eq29l/MCee8nOlAhB46tDQ oQkOsL+n30/cLCGdW75DqCqesYtD+rAfwA73QIoA6Axw7VMumBERew6SMcpJbVgu9CfI Gq5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TynigcXpBybeSxyjIjh5tzCMDz6V51e8FQfAtUXKr1I=; b=NWt8ZRZliyBrl4op6xFgbEnbTBg+VAVoCFTgm3JTt/ITZeqIuQD3dcTWqUcE1MKlVr MF46PsYnKIoNB+wl0c1Cyk3YdwWAfymgfSeOQaw9Abk1IgrVutcz95OvqkEMo36aciDx tlMgbwksH2wkfZSeKnuDchv732F0IDa1c6CXeOXy4QtIgtKFLO1dap0A3gBGMp7Fxa1Y 1hvy+EyFl68FyDQ7cuoqZC0u3/Wkol0tHKLwb3jstwCSQ9IzRA4fE2wPHHqY4/Efjtez ib0U/r8B5/dH2fpeV3jvVbu4Uz9stO2kjWRXNDv8hbBsmQNpy+rkKtaStr3taivA+iPL AztA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d125-v6si11651505pgc.94.2018.06.18.06.13.16; Mon, 18 Jun 2018 06:13:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933741AbeFRNKI (ORCPT + 99 others); Mon, 18 Jun 2018 09:10:08 -0400 Received: from mga04.intel.com ([192.55.52.120]:48585 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932585AbeFRNKH (ORCPT ); Mon, 18 Jun 2018 09:10:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jun 2018 06:10:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,239,1526367600"; d="scan'208";a="47943424" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 18 Jun 2018 06:10:03 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8A3CD212; Mon, 18 Jun 2018 16:10:04 +0300 (EEST) From: Andy Shevchenko To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , linux-raid@vger.kernel.org, Dmitry Torokhov , linux-input@vger.kernel.org, Andrew Morton , Yury Norov , linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, Joe Perches Cc: Andy Shevchenko Subject: [PATCH v3 3/5] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Date: Mon, 18 Jun 2018 16:10:01 +0300 Message-Id: <20180618131003.88110-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618131003.88110-1-andriy.shevchenko@linux.intel.com> References: <20180618131003.88110-1-andriy.shevchenko@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 8 ++++++++ lib/bitmap.c | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 1ee46f492267..acf5e8df3504 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -104,6 +104,14 @@ * contain all bit positions from 0 to 'bits' - 1. */ +/* + * Allocation and deallocation of bitmap. + * Provided in lib/bitmap.c to avoid circular dependency. + */ +extern unsigned long *bitmap_alloc(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); + /* * lib/bitmap.c provides these functions: */ diff --git a/lib/bitmap.c b/lib/bitmap.c index 33e95cd359a2..09acf2fd6a35 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -1125,6 +1126,24 @@ void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int n EXPORT_SYMBOL(bitmap_copy_le); #endif +unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags) +{ + return kmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long), flags); +} +EXPORT_SYMBOL(bitmap_alloc); + +unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags) +{ + return bitmap_alloc(nbits, flags | __GFP_ZERO); +} +EXPORT_SYMBOL(bitmap_zalloc); + +void bitmap_free(const unsigned long *bitmap) +{ + kfree(bitmap); +} +EXPORT_SYMBOL(bitmap_free); + #if BITS_PER_LONG == 64 /** * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap -- 2.17.1