From: Matthew Wilcox Date: Wed, 19 Dec 2018 13:59:58 +0000 (-0500) Subject: printf: Convert hex_string to printf_state X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=654dbf6a4a539da7dd9b9f884a5341b2dfb5f2fa;p=users%2Fwilly%2Flinux.git printf: Convert hex_string to printf_state Signed-off-by: Matthew Wilcox --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 7d606b4e0c93..9dad5d74e9f1 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -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':