From: Matthew Wilcox Date: Thu, 20 Dec 2018 21:10:50 +0000 (-0500) Subject: printf: Convert escaped_string to printf_state X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2c875a1128016806ff341c19e9f54c7fffd1cf31;p=users%2Fwilly%2Flinux.git printf: Convert escaped_string to printf_state Signed-off-by: Matthew Wilcox --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 2f4b6decc1c2..64455779fc6f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -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':