Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1608557pxb; Thu, 4 Mar 2021 16:13:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQ1l19d6RJ6VafAcxJ+qsvGikqk5DrTbAAwAiZuuCNCwmwYkiIYgjvFPqs+G23PxCrapb8 X-Received: by 2002:a6b:4109:: with SMTP id n9mr5564016ioa.43.1614903235889; Thu, 04 Mar 2021 16:13:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614903235; cv=none; d=google.com; s=arc-20160816; b=ABr2gWRQBDh2Xq6zU0KrJPuEnbAKss+hoWGWpLtwezvVN/2dqKXOZZ12jBa1X2RkeM HhV1JnR5Y6Syb8h+ZEZ8hTPiypvvFMTiLrPBS5imCjoMbRUevYbqkYr595H0Mq2snxb8 rloy4w7r4+vTakSTgPsYC+hzRNHSQWABNvt0mvjfLZAyw6/vl5D6UmSnv5KKbalWyWSn e1IHucD/7ajGujYusvPOS24BfRktE+Zif2eM0x8RYwhvlv0mybzssblYrp5KiryuKyGY csM+UK14luz1u0YHRihRPmSHBz2Lx61iGystTAgczrmos1XZBPUk9fwPx12gqDJi5+s8 X7sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=/L+KG2bxWk5C36KEvlYKfH9tb4KUk1Q4kPxjaFEbuPE=; b=Eec1ps0fuB5hJ+7CYDrl54x0qQYPXiljpiLA2QMwG2C+Ka+mBe/0+OkVc86ejmnST2 r2BpV2dj1SJLBC7CISiXK6uBoGxT4TNml+w7AzQO4mXT9NAU4HxCME5ts8ff9rKAh8fg p7yXleJhMrXktNVAFeg37Z1snEd6dP/X7rH21QHg4sNy3ILOxsnOUQtXW+OuCg3QPq9R HAhiiGnVhwj2OwQUtsl5MAbv39D6llEQEkNc3b3b6Np3VaOvkPTwH3jr9SHeo8mF3z/u K5ZFyctrgEYPGsIJJr6VHgbGOIWvmPJr5m85nzh3BrX+cRR6H2jIGp+cJKc2PkrI0VQV EXlQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c19si825428iow.0.2021.03.04.16.13.42; Thu, 04 Mar 2021 16:13:55 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241101AbhCDNEU (ORCPT + 99 others); Thu, 4 Mar 2021 08:04:20 -0500 Received: from mga04.intel.com ([192.55.52.120]:12076 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241107AbhCDNEC (ORCPT ); Thu, 4 Mar 2021 08:04:02 -0500 IronPort-SDR: aBsC3JAZAeRfOTRJ+LdnPKDg6lIkJBH0EVLHPorzwuvwAgp1xHawMwtZVfyvp07dqU/+JSloPb iQovZHCuamlA== X-IronPort-AV: E=McAfee;i="6000,8403,9912"; a="184997986" X-IronPort-AV: E=Sophos;i="5.81,222,1610438400"; d="scan'208";a="184997986" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2021 05:01:31 -0800 IronPort-SDR: rsBAzZMzBpokqlLFNORlDxZXjohLA7ZGTxLSmJFAxVgp6xQrEvaIk2BmGrEyiWDHSpMP+dowQU 4/L1nh9T017Q== X-IronPort-AV: E=Sophos;i="5.81,222,1610438400"; d="scan'208";a="507371623" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2021 05:01:26 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1lHnbX-009sd7-E0; Thu, 04 Mar 2021 15:01:23 +0200 Date: Thu, 4 Mar 2021 15:01:23 +0200 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Joel Becker , Christoph Hellwig , Shuah Khan , Linus Walleij , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Geert Uytterhoeven , Kent Gibson , Jonathan Corbet , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH v2 07/12] lib: bitmap: provide devm_bitmap_alloc() and devm_bitmap_zalloc() Message-ID: References: <20210304102452.21726-1-brgl@bgdev.pl> <20210304102452.21726-8-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210304102452.21726-8-brgl@bgdev.pl> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 04, 2021 at 11:24:47AM +0100, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > Provide managed variants of bitmap_alloc() and bitmap_zalloc(). Reviewed-by: Andy Shevchenko A few nit-picks below. > 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. > + */ One line? > +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); Both can be oneliners. > /* > * 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) One line? > +{ > + 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) One line? > +{ > + 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 > -- With Best Regards, Andy Shevchenko