aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bitmap.c
diff options
context:
space:
mode:
authorYury Norov <yury.norov@gmail.com>2021-08-06 23:02:51 +1200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-08-13 10:27:50 +0200
commit3b35f2a6a625126c57475aa56b5357d8e80b404c (patch)
treec68456dc36c315f9054e7bc61ecee4c3e389cef9 /lib/bitmap.c
parentdrivers/base/node.c: use bin_attribute to break the size limitation of cpumap ABI (diff)
downloadlinux-dev-3b35f2a6a625126c57475aa56b5357d8e80b404c.tar.xz
linux-dev-3b35f2a6a625126c57475aa56b5357d8e80b404c.zip
bitmap: extend comment to bitmap_print_bitmask/list_to_buf
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> Link: https://lore.kernel.org/r/20210806110251.560-6-song.bao.hua@hisilicon.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib/bitmap.c')
-rw-r--r--lib/bitmap.c18
1 files changed, 18 insertions, 0 deletions
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,