]> www.infradead.org Git - users/willy/linux.git/commitdiff
printf: Convert escaped_string to printf_state
authorMatthew Wilcox <willy@infradead.org>
Thu, 20 Dec 2018 21:10:50 +0000 (16:10 -0500)
committerMatthew Wilcox <willy@infradead.org>
Thu, 20 Dec 2018 21:10:50 +0000 (16:10 -0500)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
lib/vsprintf.c

index 2f4b6decc1c20ebbd563e9cc3856a0a307ecf49f..64455779fc6f969b4d9166944d528f329730fd3e 100644 (file)
@@ -1357,23 +1357,23 @@ char *ip4_addr_string_sa(char *buf, char *end, const struct sockaddr_in *sa,
 }
 
 static noinline_for_stack
-char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
-                    const char *fmt)
+char *escaped_string(struct printf_state *ps, u8 *addr)
 {
        bool found = true;
        int count = 1;
        unsigned int flags = 0;
        int len;
 
-       if (spec.field_width == 0)
-               return buf;                             /* nothing to print */
-
-       if (ZERO_OR_NULL_PTR(addr))
-               return string(buf, end, NULL, spec);    /* NULL pointer */
+       if (ps->spec.field_width == 0)
+               return ps->buf;                         /* nothing to print */
 
+       if (ZERO_OR_NULL_PTR(addr)) {
+               printf_string(ps, NULL);                /* NULL pointer */
+               return ps->buf;
+       }
 
        do {
-               switch (fmt[count++]) {
+               switch (ps->fmt[count++]) {
                case 'a':
                        flags |= ESCAPE_ANY;
                        break;
@@ -1404,16 +1404,17 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
        if (!flags)
                flags = ESCAPE_ANY_NP;
 
-       len = spec.field_width < 0 ? 1 : spec.field_width;
+       len = ps->spec.field_width < 0 ? 1 : ps->spec.field_width;
 
        /*
         * string_escape_mem() writes as many characters as it can to
         * the given buffer, and returns the total size of the output
         * had the buffer been big enough.
         */
-       buf += string_escape_mem(addr, len, buf, buf < end ? end - buf : 0, flags, NULL);
+       ps->buf += string_escape_mem(addr, len, ps->buf,
+                       ps->buf < ps->end ? ps->end - ps->buf : 0, flags, NULL);
 
-       return buf;
+       return ps->buf;
 }
 
 static noinline_for_stack
@@ -1932,7 +1933,7 @@ char *pointer(struct printf_state *ps, void *ptr)
                }
                break;
        case 'E':
-               return escaped_string(buf, end, ptr, spec, fmt);
+               return escaped_string(ps, ptr);
        case 'U':
                return uuid_string(ps, ptr);
        case 'V':