]> www.infradead.org Git - users/willy/linux.git/commitdiff
printf: Convert bitmap_string to printf_state
authorMatthew Wilcox <willy@infradead.org>
Wed, 19 Dec 2018 15:49:29 +0000 (10:49 -0500)
committerMatthew Wilcox <willy@infradead.org>
Wed, 19 Dec 2018 15:49:29 +0000 (10:49 -0500)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
lib/vsprintf.c

index 4468bbcdc1423e659130b94243b10613b59a72ef..637f1b1e472aedf01f9b83800e8f0a794e70aa17 100644 (file)
@@ -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 */