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

index 7d606b4e0c93c01881e9262732285ebb23eb96cc..9dad5d74e9f152ebf0e97cd28e912fe9f95d9201 100644 (file)
@@ -926,22 +926,23 @@ char *resource_string(struct printf_state *ps, struct resource *res)
 }
 
 static noinline_for_stack
-char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
-                const char *fmt)
+char *hex_string(struct printf_state *ps, u8 *addr)
 {
        int i, len = 1;         /* if we pass '%ph[CDN]', field width remains
                                   negative value, fallback to the default */
        char separator;
 
-       if (spec.field_width == 0)
+       if (ps->spec.field_width == 0)
                /* nothing to print */
-               return buf;
+               return ps->buf;
 
-       if (ZERO_OR_NULL_PTR(addr))
+       if (ZERO_OR_NULL_PTR(addr)) {
                /* NULL pointer */
-               return string(buf, end, NULL, spec);
+               printf_string(ps, NULL);
+               return ps->buf;
+       }
 
-       switch (fmt[1]) {
+       switch (ps->fmt[1]) {
        case 'C':
                separator = ':';
                break;
@@ -956,25 +957,25 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
                break;
        }
 
-       if (spec.field_width > 0)
-               len = min_t(int, spec.field_width, 64);
+       if (ps->spec.field_width > 0)
+               len = min_t(int, ps->spec.field_width, 64);
 
        for (i = 0; i < len; ++i) {
-               if (buf < end)
-                       *buf = hex_asc_hi(addr[i]);
-               ++buf;
-               if (buf < end)
-                       *buf = hex_asc_lo(addr[i]);
-               ++buf;
+               if (ps->buf < ps->end)
+                       *ps->buf = hex_asc_hi(addr[i]);
+               ++ps->buf;
+               if (ps->buf < ps->end)
+                       *ps->buf = hex_asc_lo(addr[i]);
+               ++ps->buf;
 
                if (separator && i != len - 1) {
-                       if (buf < end)
-                               *buf = separator;
-                       ++buf;
+                       if (ps->buf < ps->end)
+                               *ps->buf = separator;
+                       ++ps->buf;
                }
        }
 
-       return buf;
+       return ps->buf;
 }
 
 static noinline_for_stack
@@ -1893,7 +1894,7 @@ char *pointer(struct printf_state *ps, void *ptr)
        case 'r':
                return resource_string(ps, ptr);
        case 'h':
-               return hex_string(buf, end, ptr, spec, fmt);
+               return hex_string(ps, ptr);
        case 'b':
                switch (fmt[1]) {
                case 'l':