Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp789207imm; Fri, 15 Jun 2018 06:21:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIMQbDiPF4PbDOEBuW9tgAXUSGOHHV+/ScbOfnu3f8+PkahOJAop9KJafoUu+LzhSupB27k X-Received: by 2002:a63:ad08:: with SMTP id g8-v6mr1579888pgf.74.1529068884200; Fri, 15 Jun 2018 06:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529068884; cv=none; d=google.com; s=arc-20160816; b=UXnEraGsu40XjG84Grmbi2V4Qec/q0OeDRBphtz+AKTp08piJQaR3dz1xhKqIOWFRh Ufgb+sb4rAVQ3kU4/yNfpgw2wNtlXewA1OSaDBgD+haShxm3eAPnpT2got/LYL6RvZMK Gkfcs1zLUwqz2RHL2eo2zZdwYRRird3/cOhHW93Zk74Jvq3dtQCPBV2g7ORx8kZqi1J/ H8s6idmoQGZBHcnKQNuHav14NPFfAArcyV4xGMtCt9kWRfmqva039DNluxndB8xrV/LF z0jmYSnKmH57K83uSjEkUfLG0bzqly9XSMtEX+PAxqU4fm1BC6Ay3wCe3LstU5bqNh4r 7kQQ== 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=nR8XskhCnqPoRSzBhW7/ugEarw7PiqDqgfv06eQfMmwPDHoytdiR6joto98nZuSSQR 3CkTh4clG9waRtSy1VduxvZjrBMXS1suMeiox5o8uz9vUtQbEbYhoGTG3y6uc9hp9oME XaD8x+MBwb1MMu5DS22msG0cfxLvkSJ8Ckkm0AOyiZQLT2yGGeF7cyeoX4HPl/mNW4KM zPNLyNBiSdiHACvxgQWMpumSUPzVaYw2eoihNAcdmp4g9wkV9na67Q+gAtEOERHKW/DO 6iCUJMycscrhjfX3B5Ztcf9LXV57zjYZ3OAdqR4T6zSJZdmo5th4wSdIX4rrnzkWEL0U bF4w== 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 3-v6si8319732plf.84.2018.06.15.06.21.09; Fri, 15 Jun 2018 06:21:24 -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 S965835AbeFONUd (ORCPT + 99 others); Fri, 15 Jun 2018 09:20:33 -0400 Received: from mga01.intel.com ([192.55.52.88]:8738 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965798AbeFONU3 (ORCPT ); Fri, 15 Jun 2018 09:20:29 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jun 2018 06:20:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,227,1526367600"; d="scan'208";a="64853040" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 15 Jun 2018 06:20:17 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6497232B; Fri, 15 Jun 2018 16:20:18 +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 Cc: Andy Shevchenko Subject: [PATCH v2 3/5] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Date: Fri, 15 Jun 2018 16:20:15 +0300 Message-Id: <20180615132017.23889-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180615132017.23889-1-andriy.shevchenko@linux.intel.com> References: <20180615132017.23889-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