Commit 8ec3d768 authored by Rasmus Villemoes's avatar Rasmus Villemoes Committed by Linus Torvalds

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.dkSigned-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: default avatarAndy 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ce1091d4
......@@ -471,12 +471,9 @@ int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
int nmaskbits)
{
ptrdiff_t len = PAGE_SIZE - offset_in_page(buf);
int n = 0;
if (len > 1)
n = list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) :
return list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) :
scnprintf(buf, len, "%*pb\n", nmaskbits, maskp);
return n;
}
EXPORT_SYMBOL(bitmap_print_to_pagebuf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment