Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3135958pxf; Mon, 15 Mar 2021 02:16:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZclHgr2lSx5ARurhv/gwOPreuZCHoNbQ15ZTHbY+rfVXxOlkNXQXs5ARutfMpor7A33K8 X-Received: by 2002:a50:fb10:: with SMTP id d16mr29097439edq.73.1615799791813; Mon, 15 Mar 2021 02:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615799791; cv=none; d=google.com; s=arc-20160816; b=xSil4n8IRKJXe7L7XP1w7mTzgT0jM7cAAHG6oKHKx3onttLW4G45VSQnFKa4xCk3C2 sdUVv53pa9GnAD69D4iD7S9Y0D/0ODeZpPRnn/vmhSestv/PA0ITkg1hX9AYz67g/hHk N0Nq+UWJjl1K7R4g0g5KfZSKCOq0Gsez2YxVtIGEdd7WONgIpyJ3yIRZeyl/dy6Nnbzx iSD+YNDGuH9vrLCa9nx+5PcQqhSMWw0kJxF1fMURQcqV0ucJMD6NbT0rowpFDjHZtBtf 97lETHxRRMhg/gnhVav1pHqVNjvNuKFakoOWb+IH5dAi0whUaKdCtDKkuBoQF8GZdVRa QFCg== 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=I//Q3Rak1EpVNRDtRGeww40WUlM2LbS/M05ekONU4GQ=; b=rty9mqT1pxy6zuv8P0Br5nBXxt80+3TamatezJKDIaB00cwM5fR497n2uZuNlCC4Ge ok3WMBRjQfJS/DWhCAft8CpeE+al6rhYFEMS6joQgt5Ab13LY5Ry7NNRmgb/38jW3bdN moS0kFNEBuplqvgJJSMKtkBphIJnp/A2fRZtNueUSKww1D7G0AdxPthOvM2QDddp5xod YNSy0KTD1HPzfuKrP9bDQg6H1aFMuvzG5C9f7QqQOMkEn7QfNvjLWO/UCz5Dur35ge6x OufVvSRNaB/uw3nW9KMIAYDzovdhkNT4SK0UUu4Wj7c0GG2w+YrfygfBrXqMXxuVHRk5 Pgjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=f1gaT8JO; 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 l12si10649526ejn.151.2021.03.15.02.16.09; Mon, 15 Mar 2021 02:16:31 -0700 (PDT) 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=f1gaT8JO; 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 S229831AbhCOJOq (ORCPT + 99 others); Mon, 15 Mar 2021 05:14:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbhCOJOU (ORCPT ); Mon, 15 Mar 2021 05:14:20 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C275FC06175F for ; Mon, 15 Mar 2021 02:14:19 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id o16so5279297wrn.0 for ; Mon, 15 Mar 2021 02:14:19 -0700 (PDT) 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=I//Q3Rak1EpVNRDtRGeww40WUlM2LbS/M05ekONU4GQ=; b=f1gaT8JOF07kfR1GIVt3bonS3qRiBTNvSrfnLU1MmbY4X4lmKobMadPhA7/RJHvntX vHqhaEUhh37jioU2zjGZ9KwpS8T21BakJizbqkFr1gLTdA5wlidamYFv2KF4k1jGBJ6g IqiLpigO9f+o7l2+urpFnArW8+nop+4rkPlBKo2T30Lj7vYU7EWZcTannlhJMleMXLXY rJrjSqyVDyxTobKo47ZCta1N/GMyzNRAlNw1+2tb3HJjyrIKXxHtIT8U468ZxnEfUiKc fSDGZJATEReXAAr1hfNms+W4TOsxGoQdhcCiP32hJDtrg68IbYACwqtr/V1QV9SqzGSW DddQ== 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=I//Q3Rak1EpVNRDtRGeww40WUlM2LbS/M05ekONU4GQ=; b=i5xBzSfWVPjoD04Zjs2TaH2033xVcbmkrBrVcahwqMNhzbQZWa+QsmUjNUdE9dTo5k 8BP3FqJrYPFAxr2cRlI4fEYtp59wZ1C+IGaQCyLtga/QF0imI1MhTMTHok/2TT0ma6ZZ 4UQVoJOgOQA1Xn8XInRyemI/6VPbnsbmqABsqo5RcL0gDbG17a1OH1ATXfqtgKAJe6of GZMUb+4uOfyzy0yVsQWSwzn2MPcVpMn1MRvuqlt3HIIy6oMZAmhDFn5wYS4P966l4v1i FEAkWxJQpXHNsuXWp8qfjrDJCGqxuHzeWIimG64B9X7C4OxdrvOtk+ldsBdfQm/hskvH fBog== X-Gm-Message-State: AOAM530Teuu6r98pl3vG+Z2oYs/g61AkeKPlYbcA/A2aefiarsk8FGCL TcpijjFjcO0cHGk9kLATwm958Q== X-Received: by 2002:a5d:6684:: with SMTP id l4mr26313900wru.381.1615799657607; Mon, 15 Mar 2021 02:14:17 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-149-6.w2-15.abo.wanadoo.fr. [2.15.231.6]) by smtp.gmail.com with ESMTPSA id z3sm17978822wrw.96.2021.03.15.02.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 02:14:17 -0700 (PDT) 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 , Greg Kroah-Hartman Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 07/11] lib: bitmap: provide devm_bitmap_alloc() and devm_bitmap_zalloc() Date: Mon, 15 Mar 2021 10:13:56 +0100 Message-Id: <20210315091400.13772-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210315091400.13772-1-brgl@bgdev.pl> References: <20210315091400.13772-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 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..27e08c0e547e 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_GPL(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_GPL(devm_bitmap_zalloc); + #if BITS_PER_LONG == 64 /** * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap -- 2.30.1