Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp309427ybl; Tue, 28 Jan 2020 03:39:51 -0800 (PST) X-Google-Smtp-Source: APXvYqzlTFBSJjLZfcZ/pc0aZfxZ55GRgeR8r5Ywz9FE/gOrQfXFzGr5yKMrDWhUSqzpXoMO8NPi X-Received: by 2002:aca:cc55:: with SMTP id c82mr2380388oig.165.1580211591435; Tue, 28 Jan 2020 03:39:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580211591; cv=none; d=google.com; s=arc-20160816; b=WpxcsKt/wom2D8QokfXztIdCuZ+JRc8wq+8l8LoYy7EnXztNgg026DdThZfqAImAtp tZOhoABmfD8h7yJNd9W91p0t96VXZhqSAnGtABNaabahDgi2eguyccrU6isRt+HrP9vA vsvPFi4iSnMohe29f5+Ou4nKjOzhRSMH5TywJm4xheTNSMhgmY+cYUbAYuJO4+25i7lX 4HpZ0eUtauiXq87cb601qCmK9Jd5fgMpf/OyA6RyLlo1/Gfeho83MhYUX++NbWyOkESQ hIMfPSgLw15Y5osIXZsDcLv2js+X6d93Z1kqMVxzZE1rMMwDkumRsCc4s6uVK/Abf3SL 27/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=shek/n2yaJ4xNGyr8p8VRMr5B9/J6o+UNlVfe5LW8Wk=; b=GvwGhQQVyrPt/dNqEGNDPonPJgAPuVCNOjgODEaCxw27dvIDL4zvLDSzKDNEhV1tkM PM/NLt42qKk0/9Jb43QUHGwWCViJP5AeYlax1+EivvGiJwf4fAMYvoptZxBrkVEwL/e9 taT9yu5+a8LzVqzfxiWYnjUvzt6uzwlj74ZdW4krGzbbKEUlofeGA9dw7JU9fWJ7PR0i byL1RFp22CJNhTnH1tGRUcxa/6XuThqM+UXAq7FJyecawQtVgX2p5bI0e3IZO4UpKh0G 3+0mQNywYAXXSkEo23ovYcoGrBZ2M8J1JdtjggSQUR6fvB48yJZ3BL8KXtHOa3ADtktV 6JZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mx5ogHr3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si10271160otg.248.2020.01.28.03.39.40; Tue, 28 Jan 2020 03:39:51 -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=@linaro.org header.s=google header.b=mx5ogHr3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726066AbgA1Lin (ORCPT + 99 others); Tue, 28 Jan 2020 06:38:43 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:44609 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726002AbgA1Lim (ORCPT ); Tue, 28 Jan 2020 06:38:42 -0500 Received: by mail-lf1-f65.google.com with SMTP id v201so8808369lfa.11 for ; Tue, 28 Jan 2020 03:38:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=shek/n2yaJ4xNGyr8p8VRMr5B9/J6o+UNlVfe5LW8Wk=; b=mx5ogHr3Q1649qfV1I/89WFMUGNodbkAskaHwYx5cV+jARa8ihf9fCZhc01yQAfR+w JnXP1BKtt/2eCZBD7+NcbS7CE4Yfwhdf9Cx9YSmr3gIc6GfseuM9j0A0pK1TffeqjIDg dxJQpOL/b87oMxS+jzmz0E0YBDIc74+4HveLL+xaUMfoe6FSwIR+BbTIyr95KqLShCjm oupWzKprvdeQuDYTNpSk+fXXwMTxNyiZjJm0OVBSTYcWyQmRjFFZGcNimiZcVUbbUDM7 YWEEtgoBPCwI2TiiL3wP5SFOto8OVl4SFITf2ogKyERJf9tzX+lV/O7yFpo+eacRP3z/ icXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=shek/n2yaJ4xNGyr8p8VRMr5B9/J6o+UNlVfe5LW8Wk=; b=W2tgnPusBxa2As2xjvXbEe6dZcc76RSra18AVgHfuahJKrEF/zfeRmwhq903gSFVDH ergHRwAtk0w0oD7xeZ2alcEtkKx71dz0pFKe9hSC2Tiujz4gaW8DvJA72RfZhvBZ1vpS 21SZGw/94GUPsN2DIJ0W46RtDeVzgo/wAF9xRZXomQnDioWSqPYWQWW40RlUFdjPv5bm 9nyPdWo8vWC8a9Ace7DQzzfHaow5VHRJ7zSAnco2gnjYw7wtHzLUi7+6O5xC1XBzLsEj dDKRyGi7ABXBfe5RrYOoyimw9Cnc7wMu3nYD2mnw7zR+9bft4PNscAfgLVLTDQ6g2PK0 5FvQ== X-Gm-Message-State: APjAAAUU73gMjYUMFsmsyS/DiBXyMwv8N2/vzqFBY60lD0U0FSZisMD2 uylG2AV1r5S0iBWH53HDmvRtYWyOEuP5njVZRNMlZQ== X-Received: by 2002:ac2:5467:: with SMTP id e7mr2052345lfn.74.1580211518997; Tue, 28 Jan 2020 03:38:38 -0800 (PST) MIME-Version: 1.0 References: <20180630201750.2588-1-andriy.shevchenko@linux.intel.com> <20180630201750.2588-4-andriy.shevchenko@linux.intel.com> In-Reply-To: <20180630201750.2588-4-andriy.shevchenko@linux.intel.com> From: Naresh Kamboju Date: Tue, 28 Jan 2020 17:08:27 +0530 Message-ID: Subject: Re: [PATCH v4 3/5] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() To: Greg Kroah-Hartman , Sasha Levin , Andy Shevchenko Cc: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , linux-raid@vger.kernel.org, Dmitry Torokhov , linux-input@vger.kernel.org, Andrew Morton , Yury Norov , open list , mika.westerberg@linux.intel.com, Joe Perches , linux- stable , lkft-triage@lists.linaro.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 1 Jul 2018 at 01:49, Andy Shevchenko wrote: > > 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 > --- > include/linux/bitmap.h | 8 ++++++++ > lib/bitmap.c | 19 +++++++++++++++++++ > 2 files changed, 27 insertions(+) > > diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h > index 1ee46f492267..acf5e8df3504 100644 > --- a/include/linux/bitmap.h > +++ b/include/linux/bitmap.h > @@ -104,6 +104,14 @@ > * contain all bit positions from 0 to 'bits' - 1. > */ > > +/* > + * 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: > */ > diff --git a/lib/bitmap.c b/lib/bitmap.c > index 33e95cd359a2..09acf2fd6a35 100644 > --- a/lib/bitmap.c > +++ b/lib/bitmap.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -1125,6 +1126,24 @@ void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int n > 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); > + > #if BITS_PER_LONG == 64 > /** > * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap stable-rc 4.14 build failed due to these build error, lib/bitmap.c: In function 'bitmap_from_u32array': lib/bitmap.c:1133:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags) ^~~~~~~~ In file included from /srv/oe/build/tmp-lkft-glibc/work-shared/intel-corei7-64/kernel-source/lib/bitmap.c:8:0: lib/bitmap.c:1138:15: error: non-static declaration of 'bitmap_alloc' follows static declaration EXPORT_SYMBOL(bitmap_alloc); ^ include/linux/export.h:65:21: note: in definition of macro '___EXPORT_SYMBOL' extern typeof(sym) sym; \ ^~~ lib/bitmap.c:1138:1: note: in expansion of macro 'EXPORT_SYMBOL' EXPORT_SYMBOL(bitmap_alloc); ^~~~~~~~~~~~~ lib/bitmap.c:1133:16: note: previous definition of 'bitmap_alloc' was here unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags) ^~~~~~~~~~~~ In file included from /srv/oe/build/tmp-lkft-glibc/work-shared/intel-corei7-64/kernel-source/lib/bitmap.c:8:0: lib/bitmap.c:1144:15: error: non-static declaration of 'bitmap_zalloc' follows static declaration EXPORT_SYMBOL(bitmap_zalloc); ^ include/linux/export.h:65:21: note: in definition of macro '___EXPORT_SYMBOL' extern typeof(sym) sym; \ ^~~ lib/bitmap.c:1144:1: note: in expansion of macro 'EXPORT_SYMBOL' EXPORT_SYMBOL(bitmap_zalloc); ^~~~~~~~~~~~~ lib/bitmap.c:1140:16: note: previous definition of 'bitmap_zalloc' was here unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags) ^~~~~~~~~~~~~ In file included from /srv/oe/build/tmp-lkft-glibc/work-shared/intel-corei7-64/kernel-source/lib/bitmap.c:8:0: lib/bitmap.c:1150:15: error: non-static declaration of 'bitmap_free' follows static declaration EXPORT_SYMBOL(bitmap_free); ^ include/linux/export.h:65:21: note: in definition of macro '___EXPORT_SYMBOL' extern typeof(sym) sym; \ ^~~ lib/bitmap.c:1150:1: note: in expansion of macro 'EXPORT_SYMBOL' EXPORT_SYMBOL(bitmap_free); ^~~~~~~~~~~~~ lib/bitmap.c:1146:6: note: previous definition of 'bitmap_free' was here void bitmap_free(const unsigned long *bitmap) ^~~~~~~~~~~ CC drivers/char/random.o scripts/Makefile.build:326: recipe for target 'lib/bitmap.o' failed make[3]: *** [lib/bitmap.o] Error 1 Makefile:1052: recipe for target 'lib' failed make[2]: *** [lib] Error 2