From patchwork Tue Mar 9 20:59:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 396320 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham 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 098A0C433DB for ; Tue, 9 Mar 2021 21:00:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFDAB65253 for ; Tue, 9 Mar 2021 21:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbhCIVAL (ORCPT ); Tue, 9 Mar 2021 16:00:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231940AbhCIU7k (ORCPT ); Tue, 9 Mar 2021 15:59:40 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F878C06175F for ; Tue, 9 Mar 2021 12:59:40 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id c76-20020a1c9a4f0000b029010c94499aedso8125639wme.0 for ; Tue, 09 Mar 2021 12:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b9JrBKuO/UMxqLp0dR5QODxDjy8Sowg28gDkd3Cd158=; b=gNj6Q50g6ug1gUrCDzjA9E7LWc0DnilcsqHr7HBJOv7TwIV06hKwzSPWgiJdFQ3zI6 Y10x4QoKsKKn7Qj/7mhwA92T3OTe2X2ON4yI47AXu05//eR534zFAYK+H7+V6iaqGPJO j/vxPZy2oFHoH1zjg84vpNdxZUd6Nyf9nXRg9ySqn49aMo/YZairKosQ18ZpzKiZy6HC NfTcvas0X+3sQen4loVpZnsyxYAP/vDoHkhERMwBhaHrmYqryZ+jkKNpAkKsvsd84fdg T15h7wVBB3YH9zJz9MwHoP3X3xOsT2mwu6TVF/SD8bOCMWZI+NAh4xejeI+rs2vBPQYz bOsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b9JrBKuO/UMxqLp0dR5QODxDjy8Sowg28gDkd3Cd158=; b=FU6cz/sSiWYt+wdWWQyedTi1lr7obu2U/YxEkubKyRWXTA8/2rO9TQGd7Iaw910AIg b1bNkzt+VXOFA/T4pDHGHJ2IsDxTw/fx7X4TsLgtKod9yZ4Fixx0zCAq9bB+Yg5hz9Vd Omk6BSxeMOTgNpibax86hPhwOa8vL+r85yimaGjYO+eiiCgUaUKhJm335zkOEScXEc/d Fq4MXEdaqZY+iDVgONdkBZDVH/4W5486y94Vgfc+XGX+AWzSH+fWbNVvF7w7Min1tA+I +5/6R2LAyqOerZJDpjEAPo91ix8/CLlJXi/5anNvm6emYpIY11iwVWyHwYOmgMLIe1XC 3BTQ== X-Gm-Message-State: AOAM533AOTEFIcYQpPiQj/CXtfDONpZRxLGA8cMO8NBjNByN9FGaydv+ 4UD718KYoDYe3ySZ0K/uXC1qIw== X-Google-Smtp-Source: ABdhPJwk7UNTHRHU2S57yojtXBtoPnR3X8fgidczapk6qJPjcUluXTyCPbKjWKmWroltXPKxnXYd/A== X-Received: by 2002:a7b:cdef:: with SMTP id p15mr6149042wmj.0.1615323578909; Tue, 09 Mar 2021 12:59:38 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id j6sm5501305wmq.16.2021.03.09.12.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 12:59:38 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig , Shuah Khan , Linus Walleij , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Geert Uytterhoeven , Kent Gibson , Jonathan Corbet , Greg Kroah-Hartman Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v3 07/11] lib: bitmap: provide devm_bitmap_alloc() and devm_bitmap_zalloc() Date: Tue, 9 Mar 2021 21:59:17 +0100 Message-Id: <20210309205921.15992-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309205921.15992-1-brgl@bgdev.pl> References: <20210309205921.15992-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide managed variants of bitmap_alloc() and bitmap_zalloc(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- include/linux/bitmap.h | 8 ++++++++ lib/bitmap.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 3282db97e06c..73d039476fa4 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -9,6 +9,8 @@ #include #include +struct device; + /* * bitmaps provide bit arrays that consume one or more unsigned * longs. The bitmap interface and available operations are listed @@ -122,6 +124,12 @@ unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags); unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags); void bitmap_free(const unsigned long *bitmap); +/* Managed variants of the above. */ +unsigned long *devm_bitmap_alloc(struct device *dev, + unsigned int nbits, gfp_t flags); +unsigned long *devm_bitmap_zalloc(struct device *dev, + unsigned int nbits, gfp_t flags); + /* * lib/bitmap.c provides these functions: */ diff --git a/lib/bitmap.c b/lib/bitmap.c index 78f70d9007ad..b4fd7fd084c6 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1263,6 +1264,38 @@ void bitmap_free(const unsigned long *bitmap) } EXPORT_SYMBOL(bitmap_free); +static void devm_bitmap_free(void *data) +{ + unsigned long *bitmap = data; + + bitmap_free(bitmap); +} + +unsigned long *devm_bitmap_alloc(struct device *dev, + unsigned int nbits, gfp_t flags) +{ + unsigned long *bitmap; + int ret; + + bitmap = bitmap_alloc(nbits, flags); + if (!bitmap) + return NULL; + + ret = devm_add_action_or_reset(dev, devm_bitmap_free, bitmap); + if (ret) + return NULL; + + return bitmap; +} +EXPORT_SYMBOL(devm_bitmap_alloc); + +unsigned long *devm_bitmap_zalloc(struct device *dev, + unsigned int nbits, gfp_t flags) +{ + return devm_bitmap_alloc(dev, nbits, flags | __GFP_ZERO); +} +EXPORT_SYMBOL(devm_bitmap_zalloc); + #if BITS_PER_LONG == 64 /** * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap