]> www.infradead.org Git - users/willy/linux.git/commitdiff
printf: Convert device_node_string to printf_state
authorMatthew Wilcox <willy@infradead.org>
Wed, 19 Dec 2018 17:50:30 +0000 (12:50 -0500)
committerMatthew Wilcox <willy@infradead.org>
Wed, 19 Dec 2018 17:50:30 +0000 (12:50 -0500)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
lib/vsprintf.c

index c907eff51bed7f76bb0f62c338ba0a564b3d72b5..375088634bca62e9718820d2d138eb054949f9a4 100644 (file)
@@ -1667,13 +1667,13 @@ char *device_node_gen_full_name(const struct device_node *np, char *buf, char *e
 }
 
 static noinline_for_stack
-char *device_node_string(char *buf, char *end, struct device_node *dn,
-                        struct printf_spec spec, const char *fmt)
+char *device_node_string(struct printf_state *ps, struct device_node *dn)
 {
        char tbuf[sizeof("xxxx") + 1];
        const char *p;
        int ret;
-       char *buf_start = buf;
+       char *buf_start = ps->buf;
+       const char *fmt = ps->fmt + 2;
        struct property *prop;
        bool has_mult, pass;
        static const struct printf_spec num_spec = {
@@ -1683,47 +1683,51 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
                .base = 10,
        };
 
-       struct printf_spec str_spec = spec;
+       struct printf_spec str_spec = ps->spec;
        str_spec.field_width = -1;
 
-       if (!IS_ENABLED(CONFIG_OF))
-               return string(buf, end, "(!OF)", spec);
+       if (!IS_ENABLED(CONFIG_OF)) {
+               printf_string(ps, "(!OF)");
+               return ps->buf;
+       }
 
-       if ((unsigned long)dn < PAGE_SIZE)
-               return string(buf, end, "(null)", spec);
+       if ((unsigned long)dn < PAGE_SIZE) {
+               printf_string(ps, "(null)");
+               return ps->buf;
+       }
 
        /* simple case without anything any more format specifiers */
-       fmt++;
-       if (fmt[0] == '\0' || strcspn(fmt,"fnpPFcC") > 0)
+       if (fmt[0] == '\0' || strcspn(fmt, "fnpPFcC") > 0)
                fmt = "f";
 
        for (pass = false; strspn(fmt,"fnpPFcC"); fmt++, pass = true) {
                int precision;
                if (pass) {
-                       if (buf < end)
-                               *buf = ':';
-                       buf++;
+                       if (ps->buf < ps->end)
+                               *ps->buf = ':';
+                       ps->buf++;
                }
 
                switch (*fmt) {
                case 'f':       /* full_name */
-                       buf = device_node_gen_full_name(dn, buf, end);
+                       ps->buf = device_node_gen_full_name(dn, ps->buf, ps->end);
                        break;
                case 'n':       /* name */
                        p = kbasename(of_node_full_name(dn));
                        precision = str_spec.precision;
                        str_spec.precision = strchrnul(p, '@') - p;
-                       buf = string(buf, end, p, str_spec);
+                       ps->buf = string(ps->buf, ps->end, p, str_spec);
                        str_spec.precision = precision;
                        break;
                case 'p':       /* phandle */
-                       buf = number(buf, end, (unsigned int)dn->phandle, num_spec);
+                       ps->buf = number(ps->buf, ps->end,
+                                       (unsigned int)dn->phandle, num_spec);
                        break;
                case 'P':       /* path-spec */
                        p = kbasename(of_node_full_name(dn));
                        if (!p[1])
                                p = "/";
-                       buf = string(buf, end, p, str_spec);
+                       ps->buf = string(ps->buf, ps->end, p, str_spec);
                        break;
                case 'F':       /* flags */
                        tbuf[0] = of_node_check_flag(dn, OF_DYNAMIC) ? 'D' : '-';
@@ -1731,21 +1735,21 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
                        tbuf[2] = of_node_check_flag(dn, OF_POPULATED) ? 'P' : '-';
                        tbuf[3] = of_node_check_flag(dn, OF_POPULATED_BUS) ? 'B' : '-';
                        tbuf[4] = 0;
-                       buf = string(buf, end, tbuf, str_spec);
+                       ps->buf = string(ps->buf, ps->end, tbuf, str_spec);
                        break;
                case 'c':       /* major compatible string */
                        ret = of_property_read_string(dn, "compatible", &p);
                        if (!ret)
-                               buf = string(buf, end, p, str_spec);
+                               ps->buf = string(ps->buf, ps->end, p, str_spec);
                        break;
                case 'C':       /* full compatible string */
                        has_mult = false;
                        of_property_for_each_string(dn, "compatible", prop, p) {
                                if (has_mult)
-                                       buf = string(buf, end, ",", str_spec);
-                               buf = string(buf, end, "\"", str_spec);
-                               buf = string(buf, end, p, str_spec);
-                               buf = string(buf, end, "\"", str_spec);
+                                       ps->buf = string(ps->buf, ps->end, ",", str_spec);
+                               ps->buf = string(ps->buf, ps->end, "\"", str_spec);
+                               ps->buf = string(ps->buf, ps->end, p, str_spec);
+                               ps->buf = string(ps->buf, ps->end, "\"", str_spec);
 
                                has_mult = true;
                        }
@@ -1755,7 +1759,8 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
                }
        }
 
-       return widen_string(buf, buf - buf_start, end, spec);
+       printf_widen_string(ps, ps->buf - buf_start);
+       return ps->buf;
 }
 
 /*
@@ -1983,9 +1988,9 @@ char *pointer(struct printf_state *ps, void *ptr)
        case 'G':
                return flags_string(ps, ptr);
        case 'O':
-               switch (fmt[1]) {
+               switch (ps->fmt[1]) {
                case 'F':
-                       return device_node_string(buf, end, ptr, spec, fmt + 1);
+                       return device_node_string(ps, ptr);
                }
                break;
        case 'x':