Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp456069ybl; Tue, 28 Jan 2020 06:15:46 -0800 (PST) X-Google-Smtp-Source: APXvYqzS+md12VDDDTrT6fzHZbmN8aRib5/NERah29WcIOZ9OrXqoaiyLJHFQq69rjpWvVaa6zyu X-Received: by 2002:a9d:5c8a:: with SMTP id a10mr15467627oti.95.1580220945988; Tue, 28 Jan 2020 06:15:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580220945; cv=none; d=google.com; s=arc-20160816; b=BudXut0o/E1jJvjY/8RCVhj7xbKoAqsvds0uBiB2mrT7j0vwra1DwwmpzzNZku/zbn X/ys+FwKV06l7WKoY9lM9f5EPgwu0QWya8JidV6Bx+Y+4ex7vf65+j8ONlTKw7kmdwoM 83xCI4o2+mrzJVOoZcKx6q2ArmkSGA1zYll6WQgUvLvlBSU+eXuHF/WPRmoFb9BMNYMX B18cdKeUNIMDSynQFjmGwMTlO9/dbt+X0lH4hMAmTsAQzXmIz8r65XzdW2ozmqkdbEye AGSIHccTY5l0X8TG6oKKaU0EHbuu/uypiESO3pOEb8zCX2/7g4Q+xiZiTaLT+8xupgw/ utLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7mnLDARmKyAZvH/I1PpY9RtQoHQvao04cCU7tzmY1Bs=; b=Nm4X1H9SirVcpl7nJIxR0aY7b3Cs2MFipqbR2/PmcqkxpxVwrE/QcuGdgYE2GdiyOz QCNmlzHziErhDJwsFQ+Jj64vjcYQSObj8zEz7u/1nTeQDv7bAktvXy8AvlanrCdeCEm+ bu6KpcP3sycWf20E00MzeYZOj7r0ejN0oVB6FAE1gz1b7cdIIh9kt3e4lpCMDkWO/GKe jEZdHIXi7f2PHfXuiIxtR7Y0MWZMyIZ2mS8f5z/4OwJXjwFv6lecrnYel+xwakZsgS/u +ypYariFxH+qa0vCz7O+oSQsdkYHvb2arxKrAwCSWW6dh+ye1Ms59nSWRDKPlP//DdhV eUiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tlqV7gdC; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l140si2267198oib.114.2020.01.28.06.15.33; Tue, 28 Jan 2020 06:15:45 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=tlqV7gdC; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729906AbgA1OOh (ORCPT + 99 others); Tue, 28 Jan 2020 09:14:37 -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);