Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2197441imm; Sat, 30 Jun 2018 13:20:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpegLWtCfi7dB158JuXjTl9JYfBR8JW7QOuUQcf3qaNcxad1+LMXfwwad70DrGVwUT3HysYb X-Received: by 2002:a17:902:bc49:: with SMTP id t9-v6mr11793722plz.116.1530390026707; Sat, 30 Jun 2018 13:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530390026; cv=none; d=google.com; s=arc-20160816; b=p5WYzaFm1otQqkcf1AwpXnfkZ2rUIjgXOuKF6PcO4rOOdLRJOCdeEtW5MwioayrUTN bhGxjfkclAgX6JCJphK8Qb7IqPbCphXFRDCBJ9ujZmCt12jXuOBXAYV9C8o97VFMs4aL l9aQoMhQ6cLmVzUqVN+HgFC1QJDB8u6rOECXM8vZe/pwllH3YzT3pdHppJ/5/TOQWIc5 LY1gYJilN7MgYIHNtbh8oWqekYhOOqbxzk6QC4aaBfCjy7arF/6+0Ex8KaKXdwGAjIRp /j4JA1Hq1HKUDKQXXRNVoVSL7BDDoVSqa0TQ35SbKk4blOqexSYDjutgVNnSlsJf/6wk GvMQ== 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=aFjpmqUwiyW20tV9rV+ZqulZx8vW9FvRCK3quYFMBgs=; b=mZGA+TCw3wim3ma4d60y7GeEGxc94zwaqnQGA7qxP7e6r+2ACS7pmCeUWE2zLS24HS SII6n3Mq/fBjzDvV+scqMkSxTUh+pCXrwhMP5/6aFH66qt/G1a2jAagWmnlZNWUguRkx tw3PHpguXnRqaJ/cWDiri5VWPUhLe7Sh9oo+LF+aIngiWI8Nix8wx8JGXmy9YhXMH879 v27S15ercB6i282Ueyo5revdLktbyNZIFL/z3G4UmX6eIIvehA+mnfL420KXWlsYSWkl P+1ZJZrkpz0vxY5XE/Z9ywzEfCadchYlAHwrZhoZGEAnm9sCI9BBfpI+6OaPDPIJwlFS wjcg== 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 f18-v6si8192263pgd.16.2018.06.30.13.20.12; Sat, 30 Jun 2018 13:20:26 -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 S1751987AbeF3USH (ORCPT + 99 others); Sat, 30 Jun 2018 16:18:07 -0400 Received: from mga05.intel.com ([192.55.52.43]:39771 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751466AbeF3URw (ORCPT ); Sat, 30 Jun 2018 16:17:52 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jun 2018 13:17:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,291,1526367600"; d="scan'208";a="63464714" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 30 Jun 2018 13:17:48 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 589DB58D; Sat, 30 Jun 2018 23:17:51 +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 v4 3/5] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Date: Sat, 30 Jun 2018 23:17:48 +0300 Message-Id: <20180630201750.2588-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180630201750.2588-1-andriy.shevchenko@linux.intel.com> References: <20180630201750.2588-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. Note, due to multiple circular dependencies we may not provide the helpers as inliners. For now we keep them exported and, perhaps, at some point in the future we will sort out header inclusion and inheritance. 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.18.0