summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2018-10-30 18:05:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-10-31 11:54:12 -0400
commit8ec3d76863d8bb317f330bbe4bf35cded8d85f01 (patch)
treecd12cbe92cf5b52b581b96c6380d465023f918f7
parentce1091d471107dbf6f91db66a480a25950c9b9ff (diff)
lib/bitmap.c: simplify bitmap_print_to_pagebuf()
len is guaranteed to lie in [1, PAGE_SIZE]. If scnprintf is called with a buffer size of 1, it is guaranteed to return 0. So in the extremely unlikely case of having just one byte remaining in the page, let's just call scnprintf anyway. The only difference is that this will write a '\0' to that final byte in the page, but that's an improvement: We now guarantee that after the call, buf is a properly terminated C string of length exactly the return value. Link: http://lkml.kernel.org/r/20180818131623.8755-8-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Yury Norov <ynorov@caviumnetworks.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--lib/bitmap.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 5ade00d4219a..eead55aa7170 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -471,12 +471,9 @@ int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
471 int nmaskbits) 471 int nmaskbits)
472{ 472{
473 ptrdiff_t len = PAGE_SIZE - offset_in_page(buf); 473 ptrdiff_t len = PAGE_SIZE - offset_in_page(buf);
474 int n = 0;
475 474
476 if (len > 1) 475 return list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) :
477 n = list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) : 476 scnprintf(buf, len, "%*pb\n", nmaskbits, maskp);
478 scnprintf(buf, len, "%*pb\n", nmaskbits, maskp);
479 return n;
480} 477}
481EXPORT_SYMBOL(bitmap_print_to_pagebuf); 478EXPORT_SYMBOL(bitmap_print_to_pagebuf);
482 479