From: Matthew Wilcox Date: Wed, 19 Dec 2018 15:49:29 +0000 (-0500) Subject: printf: Convert bitmap_string to printf_state X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=26cdc522dcbcb16a88e526a6ffb769cdcdfb1e48;p=users%2Fwilly%2Flinux.git printf: Convert bitmap_string to printf_state Signed-off-by: Matthew Wilcox --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 4468bbcdc142..637f1b1e472a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -827,6 +827,11 @@ static const struct printf_spec default_dec_spec = { .precision = -1, }; +static const struct printf_spec default_hex_spec = { + .base = 16, + .flags = SMALL | ZEROPAD, +}; + static noinline_for_stack char *resource_string(struct printf_state *ps, struct resource *res) { @@ -979,16 +984,15 @@ char *hex_string(struct printf_state *ps, u8 *addr) } static noinline_for_stack -char *bitmap_string(char *buf, char *end, unsigned long *bitmap, - struct printf_spec spec, const char *fmt) +char *bitmap_string(struct printf_state *ps, unsigned long *bitmap) { const int CHUNKSZ = 32; - int nr_bits = max_t(int, spec.field_width, 0); + int nr_bits = max_t(int, ps->spec.field_width, 0); int i, chunksz; bool first = true; /* reused to print numbers */ - spec = (struct printf_spec){ .flags = SMALL | ZEROPAD, .base = 16 }; + ps->spec = default_hex_spec; chunksz = nr_bits & (CHUNKSZ - 1); if (chunksz == 0) @@ -1005,18 +1009,18 @@ char *bitmap_string(char *buf, char *end, unsigned long *bitmap, val = (bitmap[word] >> bit) & chunkmask; if (!first) { - if (buf < end) - *buf = ','; - buf++; + if (ps->buf < ps->end) + *ps->buf = ','; + ps->buf++; } first = false; - spec.field_width = DIV_ROUND_UP(chunksz, 4); - buf = number(buf, end, val, spec); + ps->spec.field_width = DIV_ROUND_UP(chunksz, 4); + printf_number(ps, val); chunksz = CHUNKSZ; } - return buf; + return ps->buf; } static noinline_for_stack @@ -1901,7 +1905,7 @@ char *pointer(struct printf_state *ps, void *ptr) case 'l': return bitmap_list_string(ps, ptr); default: - return bitmap_string(buf, end, ptr, spec, fmt); + return bitmap_string(ps, ptr); } case 'M': /* Colon separated: 00:01:02:03:04:05 */ case 'm': /* Contiguous: 000102030405 */