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

index 64455779fc6f969b4d9166944d528f329730fd3e..c1dffcf6d1574f707315fdb0525f0eedcf753afc 100644 (file)
@@ -1260,8 +1260,7 @@ char *ip4_addr_string(char *buf, char *end, const u8 *addr,
 }
 
 static noinline_for_stack
-char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa,
-                        struct printf_spec spec, const char *fmt)
+char *ip6_addr_string_sa(struct printf_state *ps, const struct sockaddr_in6 *sa)
 {
        bool have_p = false, have_s = false, have_f = false, have_c = false;
        char ip6_addr[sizeof("[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255]") +
@@ -1269,12 +1268,12 @@ char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa,
                      sizeof("%1234567890")];
        char *p = ip6_addr, *pend = ip6_addr + sizeof(ip6_addr);
        const u8 *addr = (const u8 *) &sa->sin6_addr;
-       char fmt6[2] = { fmt[0], '6' };
+       char fmt6[2] = { ps->fmt[0], '6' };
        u8 off = 0;
 
-       fmt++;
-       while (isalpha(*++fmt)) {
-               switch (*fmt) {
+       ps->fmt++;
+       while (isalpha(*++ps->fmt)) {
+               switch (*ps->fmt) {
                case 'p':
                        have_p = true;
                        break;
@@ -1305,20 +1304,21 @@ char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa,
 
        if (have_p) {
                *p++ = ':';
-               p = number(p, pend, ntohs(sa->sin6_port), spec);
+               p = number(p, pend, ntohs(sa->sin6_port), ps->spec);
        }
        if (have_f) {
                *p++ = '/';
                p = number(p, pend, ntohl(sa->sin6_flowinfo &
-                                         IPV6_FLOWINFO_MASK), spec);
+                                         IPV6_FLOWINFO_MASK), ps->spec);
        }
        if (have_s) {
                *p++ = '%';
-               p = number(p, pend, sa->sin6_scope_id, spec);
+               p = number(p, pend, sa->sin6_scope_id, ps->spec);
        }
        *p = '\0';
 
-       return string(buf, end, ip6_addr, spec);
+       printf_string(ps, ip6_addr);
+       return ps->buf;
 }
 
 static noinline_for_stack
@@ -1926,9 +1926,10 @@ char *pointer(struct printf_state *ps, void *ptr)
                        case AF_INET:
                                return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt);
                        case AF_INET6:
-                               return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt);
+                               return ip6_addr_string_sa(ps, &sa->v6);
                        default:
-                               return string(buf, end, "(invalid address)", spec);
+                               printf_string(ps, "(invalid address)");
+                               return ps->buf;
                        }}
                }
                break;