linux-kernel.vger.kernel.org archive mirror
 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 v8 5/5] bitmap: extend comment to bitmap_print_to_buf
Date: Thu, 29 Jul 2021 17:42:08 +1200	[thread overview]
Message-ID: <20210729054208.1800-6-song.bao.hua@hisilicon.com> (raw)
In-Reply-To: <20210729054208.1800-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 56bcffe2fa8c..608b79eabd43 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -545,6 +545,24 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf);
  * mainly serves bin_attribute which doesn't work with exact one page, 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_to_buf(bool list, char *buf, const unsigned long *maskp,
-- 
2.25.1


  parent reply	other threads:[~2021-07-29  5:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29  5:42 [PATCH v8 0/5] use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-07-29  5:42 ` [PATCH v8 1/5] cpumask: introduce cpumap_print_to_buf to support large bitmask and list Barry Song
2021-08-05 12:52   ` Greg KH
2021-08-05 23:05     ` Song Bao Hua (Barry Song)
2021-08-06  4:46       ` Greg KH
2021-07-29  5:42 ` [PATCH v8 2/5] topology: use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-07-29  5:42 ` [PATCH v8 3/5] drivers/base/node.c: " Barry Song
2021-07-29  5:42 ` [PATCH v8 4/5] lib: test_bitmap: add bitmap_print_to_buf test cases Barry Song
2021-07-29  5:42 ` Barry Song [this message]
2021-07-29 17:50 ` [PATCH v8 0/5] use bin_attribute to break the size limitation of cpumap ABI Andrew Morton
2021-07-30  5:22   ` 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=20210729054208.1800-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 v8 5/5] bitmap: extend comment to bitmap_print_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).