From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4783DC2D0DB for ; Tue, 28 Jan 2020 14:41:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1CE632173E for ; Tue, 28 Jan 2020 14:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580222463; bh=brjujh9/asiNKUHrWJONIUMMD6cFhdS8tLGrvGYJw6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=kMoizvJEZ+ZUgmwxQMaTLTD2S3HxEgqmJ0jU/fPJyU9hzgxS52tPNYWhfAdcDy+58 zLya2E+iSL6amor6R3wruDKSZIfQR6wouQ2sksbZ61dDTzggySnYSCcl34W8QLRlrC uEbSgRoob8MB1IND9q2B8wwezbGWjkJv37GR7jEg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729910AbgA1OOi (ORCPT ); Tue, 28 Jan 2020 09:14:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:36762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727976AbgA1OOd (ORCPT ); Tue, 28 Jan 2020 09:14:33 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A789A2468D; Tue, 28 Jan 2020 14:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580220873; bh=brjujh9/asiNKUHrWJONIUMMD6cFhdS8tLGrvGYJw6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tlqV7gdCMYN4KEuOJfCquH2JKBF/z+sElFttWTtp344jUqCxRocHLnva9eo7rzY5+ S5EyhFjFeP2srt8WztrWPePVAYE/+P07065L7F+Hb0Yqt84ETskKk2ZXvCCyBOqKOj jkWDUZVGO9sank3l/vZWneqI9WasELa4f6A6MfKY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Dmitry Torokhov Subject: [PATCH 4.4 180/183] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() Date: Tue, 28 Jan 2020 15:06:39 +0100 Message-Id: <20200128135847.718431075@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135829.486060649@linuxfoundation.org> References: <20200128135829.486060649@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Shevchenko commit c42b65e363ce97a828f81b59033c3558f8fa7f70 upstream. 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 Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- include/linux/bitmap.h | 8 ++++++++ lib/bitmap.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -84,6 +84,14 @@ */ /* + * 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: */ --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -1081,3 +1082,22 @@ void bitmap_copy_le(unsigned long *dst, } 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);