LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Barry Song <song.bao.hua@hisilicon.com>
To: <andriy.shevchenko@linux.intel.com>, <yury.norov@gmail.com>,
<gregkh@linuxfoundation.org>, <linux-kernel@vger.kernel.org>
Cc: <akpm@linux-foundation.org>, <dave.hansen@intel.com>,
<linux@rasmusvillemoes.dk>, <rafael@kernel.org>,
<rdunlap@infradead.org>, <agordeev@linux.ibm.com>,
<sbrivio@redhat.com>, <jianpeng.ma@intel.com>,
<valentin.schneider@arm.com>, <peterz@infradead.org>,
<bristot@redhat.com>, <guodong.xu@linaro.org>,
<tangchengchang@huawei.com>, <prime.zeng@hisilicon.com>,
<yangyicong@huawei.com>, <tim.c.chen@linux.intel.com>,
<linuxarm@huawei.com>, Barry Song <song.bao.hua@hisilicon.com>
Subject: [PATCH v9 5/5] bitmap: extend comment to bitmap_print_bitmask/list_to_buf
Date: Fri, 6 Aug 2021 23:02:51 +1200 [thread overview]
Message-ID: <20210806110251.560-6-song.bao.hua@hisilicon.com> (raw)
In-Reply-To: <20210806110251.560-1-song.bao.hua@hisilicon.com>
From: Yury Norov <yury.norov@gmail.com>
Extend comment to new function to warn potential users about caveats.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
---
lib/bitmap.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 73746d96af81..663dd81967d4 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -568,6 +568,24 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
* and it can break the size limit of converted decimal list and hexadecimal
* bitmask.
*
+ * WARNING!
+ *
+ * This function is not a replacement for sprintf() or bitmap_print_to_pagebuf().
+ * It is intended to workaround sysfs limitations discussed above and should be
+ * used carefully in general case for the following reasons:
+ * - Time complexity is O(nbits^2/count), comparing to O(nbits) for snprintf().
+ * - Memory complexity is O(nbits), comparing to O(1) for snprintf().
+ * - @off and @count are NOT offset and number of bits to print.
+ * - If printing part of bitmap as list, the resulting string is not a correct
+ * list representation of bitmap. Particularly, some bits within or out of
+ * related interval may be erroneously set or unset. The format of the string
+ * may be broken, so bitmap_parselist-like parser may fail parsing it.
+ * - If printing the whole bitmap as list by parts, user must ensure the order
+ * of calls of the function such that the offset is incremented linearly.
+ * - If printing the whole bitmap as list by parts, user must keep bitmap
+ * unchanged between the very first and very last call. Otherwise concatenated
+ * result may be incorrect, and format may be broken.
+ *
* Returns the number of characters actually printed to @buf
*/
int bitmap_print_bitmask_to_buf(char *buf, const unsigned long *maskp,
--
2.25.1
next prev parent reply other threads:[~2021-08-06 11:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 11:02 [PATCH v9 0/5] use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-08-06 11:02 ` [PATCH v9 1/5] cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list Barry Song
2021-08-06 13:22 ` Greg KH
2021-08-06 19:39 ` Song Bao Hua (Barry Song)
2021-08-10 13:24 ` Song Bao Hua (Barry Song)
2021-08-06 11:02 ` [PATCH v9 2/5] lib: test_bitmap: add bitmap_print_bitmask/list_to_buf test cases Barry Song
2021-08-06 17:51 ` kernel test robot
2021-08-06 18:04 ` Andy Shevchenko
2021-08-06 19:47 ` Max Filippov
2021-08-06 11:02 ` [PATCH v9 3/5] topology: use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-08-06 11:02 ` [PATCH v9 4/5] drivers/base/node.c: " Barry Song
2021-08-06 11:02 ` Barry Song [this message]
2021-08-12 4:44 ` [PATCH v9 0/5] " Barry Song
2021-08-13 8:32 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210806110251.560-6-song.bao.hua@hisilicon.com \
--to=song.bao.hua@hisilicon.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bristot@redhat.com \
--cc=dave.hansen@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=guodong.xu@linaro.org \
--cc=jianpeng.ma@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=linuxarm@huawei.com \
--cc=peterz@infradead.org \
--cc=prime.zeng@hisilicon.com \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=sbrivio@redhat.com \
--cc=tangchengchang@huawei.com \
--cc=tim.c.chen@linux.intel.com \
--cc=valentin.schneider@arm.com \
--cc=yangyicong@huawei.com \
--cc=yury.norov@gmail.com \
--subject='Re: [PATCH v9 5/5] bitmap: extend comment to bitmap_print_bitmask/list_to_buf' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).