lib/vsprintf: Deduplicate pointer_string()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 16 Feb 2018 21:07:08 +0000 (23:07 +0200)
committerPetr Mladek <pmladek@suse.com>
Wed, 11 Apr 2018 09:17:06 +0000 (11:17 +0200)
There is an exact code at the end of ptr_to_id().
Replace it by calling pointer_string() directly.

This is followup to the commit ad67b74d2469 ("printk: hash addresses
printed with %p").

Cc: Tobin C. Harding <me@tobin.cc>
Link: http://lkml.kernel.org/r/20180216210711.79901-6-andriy.shevchenko@linux.intel.com
To: "Tobin C . Harding" <me@tobin.cc>
To: linux@rasmusvillemoes.dk
To: Joe Perches <joe@perches.com>
To: linux-kernel@vger.kernel.org
To: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
lib/vsprintf.c

index 87dbced51b1afa012f7078c5261659465381f327..9004bbb3d84d955bb7f79af746ae8ee1f9c33cfe 100644 (file)
@@ -1367,13 +1367,6 @@ static noinline_for_stack
 char *restricted_pointer(char *buf, char *end, const void *ptr,
                         struct printf_spec spec)
 {
-       spec.base = 16;
-       spec.flags |= SMALL;
-       if (spec.field_width == -1) {
-               spec.field_width = 2 * sizeof(ptr);
-               spec.flags |= ZEROPAD;
-       }
-
        switch (kptr_restrict) {
        case 0:
                /* Always print %pK values */
@@ -1385,8 +1378,11 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,
                 * kptr_restrict==1 cannot be used in IRQ context
                 * because its test for CAP_SYSLOG would be meaningless.
                 */
-               if (in_irq() || in_serving_softirq() || in_nmi())
+               if (in_irq() || in_serving_softirq() || in_nmi()) {
+                       if (spec.field_width == -1)
+                               spec.field_width = 2 * sizeof(ptr);
                        return string(buf, end, "pK-error", spec);
+               }
 
                /*
                 * Only print the real pointer value if the current
@@ -1411,7 +1407,7 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,
                break;
        }
 
-       return number(buf, end, (unsigned long)ptr, spec);
+       return pointer_string(buf, end, ptr, spec);
 }
 
 static noinline_for_stack
@@ -1686,10 +1682,9 @@ early_initcall(initialize_ptr_random);
 static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
 {
        unsigned long hashval;
-       const int default_width = 2 * sizeof(ptr);
 
        if (unlikely(!have_filled_random_ptr_key)) {
-               spec.field_width = default_width;
+               spec.field_width = 2 * sizeof(ptr);
                /* string length must be less than default_width */
                return string(buf, end, "(ptrval)", spec);
        }
@@ -1704,15 +1699,7 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
 #else
        hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
 #endif
-
-       spec.flags |= SMALL;
-       if (spec.field_width == -1) {
-               spec.field_width = default_width;
-               spec.flags |= ZEROPAD;
-       }
-       spec.base = 16;
-
-       return number(buf, end, hashval, spec);
+       return pointer_string(buf, end, (const void *)hashval, spec);
 }
 
 /*