Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1320539pxb; Thu, 4 Mar 2021 08:26:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/UH2hxwpINjxYdwi9P8kwaeDS2SFm7McPU1MRr6rGm7VCfwQNwoB/3k/VYzGdH+H8QDCC X-Received: by 2002:a17:906:b316:: with SMTP id n22mr4910889ejz.249.1614875195223; Thu, 04 Mar 2021 08:26:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614875195; cv=none; d=google.com; s=arc-20160816; b=ZW3SAx6Dq30X5qbwI/cEUnKh/Prd00x5iXSQ70Wxee2eEKK9wHsk03SQ7lIx4T3TIQ 8qsBvB2oKuQtG/KfTKe0Wv3xn6S+Ap59/gEnGcYEviqyjy0U9IK5MOQhrsO6iW7iAV/v hP8AfQWh02HtP8iJYoCvG1IxZ6fshf3grR+8oVb1C4r1Imr/S4UpUev0tZi6yh/9WP9E 5jEYykmY2FmdRUGf/xIFr2Ya77QjwBl7cEimKnizuoTJ74EFpXh76eoxskow3hmyCKMX di7Psl4B74vrUwM4uqhh86/nh6Y32QqkcK2KOSFdRhwftu67yY2mnbqIYuKCp6TMf2HD LWXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zgmBZ3NhwrAFJO5K/6mUJqd+FqbPtvHWFuPSvB1rVno=; b=j7Il+WTJyL5ZVZpYnrrRvuF6U8AtoZq9kucYn3+xaRUXQ2mDdEbqiR9IrC8pOGN+8g tlvomsMZQaH54ebYCpo2oKLS3emSjSmqlW93emhrzNlUUjFYC5DhYT/lJltSYCPyFcCr tiWohpPVQLOHDPVDUal7uNtd9pO1W2oopnY0gUwKUNFSLJa7qqPn1/kTM1NgS5kSTaH8 6fENZXCWGtJ6vX0no4MiBAZCU3IMrUnN6Q9kdAq6X486crFuRdt80y0b05BpjpEoQ0zL 1rJLCiV29jv0ym1A3VGOkJq2De9OmBwFmniaesyqgdQaIuB9Yw7YXZTmMS6dh/ma3WAi E/wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=PkWRHiRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 38si5208572edr.200.2021.03.04.08.26.12; Thu, 04 Mar 2021 08:26:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=PkWRHiRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238696AbhCDKcf (ORCPT + 99 others); Thu, 4 Mar 2021 05:32:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238659AbhCDKcI (ORCPT ); Thu, 4 Mar 2021 05:32:08 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4A1AC0613E5 for ; Thu, 4 Mar 2021 02:30:13 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id j2so14171144wrx.9 for ; Thu, 04 Mar 2021 02:30:13 -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=zgmBZ3NhwrAFJO5K/6mUJqd+FqbPtvHWFuPSvB1rVno=; b=PkWRHiRLD+YMkJpjEQ+Auf3+aLRwhQw3pzL+dX7Olf+ktGDhvHpbFJzjIWK/lgsb7F iCIq5HbuqX7xOk8gIOL4B2oDf/kyb8pGKDNSb22rvwqmnq9uuLje5Hts6OzUKkuQuNFL gyPZz7WQL5e/Qg3Ypp/G/J40mGn8azHs8XsFCTBMIUtyPY2/gIplOlFxzyFAUvSfLLa+ HNn1YxF18H9EOZ0XAVu+A/FJVNZUMqT2RQe/QBp0sht0RT1z4Qz3s1bxE3fuxw93QP3S ToR6tfdbQ8k1j5PEGTRYK0puO9BliZ3qGUEg/rjMGxaywcb/mi9xJAmijZk/Itsy4Ki5 58nA== 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=zgmBZ3NhwrAFJO5K/6mUJqd+FqbPtvHWFuPSvB1rVno=; b=kcibjnwsv95PMgbpC1uLBwBCjeHSCMt8T6hKh0dsSw/JqA4sTEGOJQq1M6/ldZabfN 5TrJO6sFFBewaAJYR1qkq0zkYz9z+D3a/syrF33RF7YfBAufVt3N34btzbRiIPYAlbFe z5LpoKReFmF2BIzLJezYXOedEni+QqbHa+brCHXohy4YiVUi6jRKYe6E7hkifVkIbx+4 AP1F1+w82RPb0rQS7+JtQxA/tJTBZ1Z+PmxyHOaMCRySrE7jNfY0zyaegfMgEfOj9E9W fkgI+1EzYHRZHp3mzZlpblLAEYZZ3XiYUDgHBW6P9BCrqteCD9nfcMb4DzRUEKXACYDN Ediw== X-Gm-Message-State: AOAM532JCsrYCr/x8XzCHQV1PNVIW4gu7Io+6NIVoFY+dIZTujy7/73Z uNjqMy+NVDTBy6FL3I61IrZMMQ== X-Received: by 2002:adf:b60e:: with SMTP id f14mr3247833wre.99.1614853812430; Thu, 04 Mar 2021 02:30:12 -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 f7sm35501854wre.78.2021.03.04.02.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 02:30:12 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig , Shuah Khan , Linus Walleij , Andy Shevchenko , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Geert Uytterhoeven , Kent Gibson , Jonathan Corbet Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 07/12] lib: bitmap: provide devm_bitmap_alloc() and devm_bitmap_zalloc() Date: Thu, 4 Mar 2021 11:24:47 +0100 Message-Id: <20210304102452.21726-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210304102452.21726-1-brgl@bgdev.pl> References: <20210304102452.21726-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Provide managed variants of bitmap_alloc() and bitmap_zalloc(). Signed-off-by: Bartosz Golaszewski --- include/linux/bitmap.h | 10 ++++++++++ lib/bitmap.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 3282db97e06c..e41c622db1b8 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,14 @@ 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 -- 2.29.1