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

index 46dffe1d7108a189d99855b420bd36bab29623e4..bce6174074c20b3c0dc1e1e380a55512726bbde1 100644 (file)
@@ -690,8 +690,7 @@ static int __init initialize_ptr_random(void)
 early_initcall(initialize_ptr_random);
 
 /* Maps a pointer to a 32 bit unique identifier. */
-static char *ptr_to_id(char *buf, char *end, const void *ptr,
-                      struct printf_spec spec)
+static char *ptr_to_id(struct printf_state *ps, const void *ptr)
 {
        const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)";
        unsigned long hashval;
@@ -699,13 +698,15 @@ static char *ptr_to_id(char *buf, char *end, const void *ptr,
        /* When debugging early boot use non-cryptographically secure hash. */
        if (unlikely(debug_boot_weak_hash)) {
                hashval = hash_long((unsigned long)ptr, 32);
-               return pointer_string(buf, end, (const void *)hashval, spec);
+               return pointer_string(ps->buf, ps->end, (const void *)hashval,
+                               ps->spec);
        }
 
        if (static_branch_unlikely(&not_filled_random_ptr_key)) {
-               spec.field_width = 2 * sizeof(ptr);
+               ps->spec.field_width = 2 * sizeof(ptr);
                /* string length must be less than default_width */
-               return string(buf, end, str, spec);
+               printf_string(ps, str);
+               return ps->buf;
        }
 
 #ifdef CONFIG_64BIT
@@ -718,7 +719,8 @@ static char *ptr_to_id(char *buf, char *end, const void *ptr,
 #else
        hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
 #endif
-       return pointer_string(buf, end, (const void *)hashval, spec);
+       return pointer_string(ps->buf, ps->end, (const void *)hashval,
+                       ps->spec);
 }
 
 static noinline_for_stack
@@ -1527,7 +1529,7 @@ char *netdev_bits(struct printf_state *ps, const void *addr)
                size = sizeof(netdev_features_t);
                break;
        default:
-               return ptr_to_id(ps->buf, ps->end, addr, ps->spec);
+               return ptr_to_id(ps, addr);
        }
 
        return special_hex_number(ps, num, size);
@@ -1569,7 +1571,7 @@ char *clock(struct printf_state *ps, struct clk *clk)
                printf_string(ps, __clk_get_name(clk));
                return ps->buf;
 #else
-               return ptr_to_id(ps->buf, ps->end, clk, ps->spec);
+               return ptr_to_id(ps, clk);
 #endif
        }
 }
@@ -1986,7 +1988,7 @@ char *pointer(struct printf_state *ps, void *ptr)
        }
 
        /* default is to _not_ leak addresses, hash before printing */
-       return ptr_to_id(buf, end, ptr, spec);
+       return ptr_to_id(ps, ptr);
 }
 
 void printf_pointer(struct printf_state *ps, void *ptr)