Skip to content

Commit 3b35f2a

Browse files
YuryNorovgregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Barry Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 75bd50f commit 3b35f2a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/bitmap.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,24 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
568568
* and it can break the size limit of converted decimal list and hexadecimal
569569
* bitmask.
570570
*
571+
* WARNING!
572+
*
573+
* This function is not a replacement for sprintf() or bitmap_print_to_pagebuf().
574+
* It is intended to workaround sysfs limitations discussed above and should be
575+
* used carefully in general case for the following reasons:
576+
* - Time complexity is O(nbits^2/count), comparing to O(nbits) for snprintf().
577+
* - Memory complexity is O(nbits), comparing to O(1) for snprintf().
578+
* - @off and @count are NOT offset and number of bits to print.
579+
* - If printing part of bitmap as list, the resulting string is not a correct
580+
* list representation of bitmap. Particularly, some bits within or out of
581+
* related interval may be erroneously set or unset. The format of the string
582+
* may be broken, so bitmap_parselist-like parser may fail parsing it.
583+
* - If printing the whole bitmap as list by parts, user must ensure the order
584+
* of calls of the function such that the offset is incremented linearly.
585+
* - If printing the whole bitmap as list by parts, user must keep bitmap
586+
* unchanged between the very first and very last call. Otherwise concatenated
587+
* result may be incorrect, and format may be broken.
588+
*
571589
* Returns the number of characters actually printed to @buf
572590
*/
573591
int bitmap_print_bitmask_to_buf(char *buf, const unsigned long *maskp,

0 commit comments

Comments
 (0)