Commit 3cab1e71 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Linus Torvalds

lib/vsprintf: refactor duplicate code to special_hex_number()

special_hex_number() is a helper to print a fixed size type in a hex
format with '0x' prefix, zero padding, and small letters.  In the module
we have already several copies of such code.  Consolidate them under
special_hex_number() helper.

There are couple of differences though.

It seems nobody cared about the output in case of CONFIG_KALLSYMS=n,
when printing symbol address, because the asked field width is not
enough to care last 2 characters in the string represantation of the
pointer.  Fixed here.

The %pNF specifier used to be allowed with a specific field width,
though there is neither any user of it nor mention the possibility in
the documentation.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 64c734be
...@@ -515,6 +515,20 @@ char *number(char *buf, char *end, unsigned long long num, ...@@ -515,6 +515,20 @@ char *number(char *buf, char *end, unsigned long long num,
return buf; return buf;
} }
static noinline_for_stack
char *special_hex_number(char *buf, char *end, unsigned long long num, int size)
{
struct printf_spec spec;
spec.type = FORMAT_TYPE_PTR;
spec.field_width = 2 + 2 * size; /* 0x + hex */
spec.flags = SPECIAL | SMALL | ZEROPAD;
spec.base = 16;
spec.precision = -1;
return number(buf, end, num, spec);
}
static void move_right(char *buf, char *end, unsigned len, unsigned spaces) static void move_right(char *buf, char *end, unsigned len, unsigned spaces)
{ {
size_t size; size_t size;
...@@ -670,11 +684,7 @@ char *symbol_string(char *buf, char *end, void *ptr, ...@@ -670,11 +684,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
return string(buf, end, sym, spec); return string(buf, end, sym, spec);
#else #else
spec.field_width = 2 * sizeof(void *); return special_hex_number(buf, end, value, sizeof(void *));
spec.flags |= SPECIAL | SMALL | ZEROPAD;
spec.base = 16;
return number(buf, end, value, spec);
#endif #endif
} }
...@@ -1336,39 +1346,33 @@ char *uuid_string(char *buf, char *end, const u8 *addr, ...@@ -1336,39 +1346,33 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
} }
static static
char *netdev_feature_string(char *buf, char *end, const u8 *addr, char *netdev_feature_string(char *buf, char *end, const void *addr)
struct printf_spec spec)
{ {
spec.flags |= SPECIAL | SMALL | ZEROPAD; unsigned long long num = *(const netdev_features_t *)addr;
if (spec.field_width == -1) int size = sizeof(netdev_features_t);
spec.field_width = 2 + 2 * sizeof(netdev_features_t);
spec.base = 16;
return number(buf, end, *(const netdev_features_t *)addr, spec); return special_hex_number(buf, end, num, size);
} }
static noinline_for_stack static noinline_for_stack
char *address_val(char *buf, char *end, const void *addr, char *address_val(char *buf, char *end, const void *addr, const char *fmt)
struct printf_spec spec, const char *fmt)
{ {
unsigned long long num; unsigned long long num;
int size;
spec.flags |= SPECIAL | SMALL | ZEROPAD;
spec.base = 16;
switch (fmt[1]) { switch (fmt[1]) {
case 'd': case 'd':
num = *(const dma_addr_t *)addr; num = *(const dma_addr_t *)addr;
spec.field_width = sizeof(dma_addr_t) * 2 + 2; size = sizeof(dma_addr_t);
break; break;
case 'p': case 'p':
default: default:
num = *(const phys_addr_t *)addr; num = *(const phys_addr_t *)addr;
spec.field_width = sizeof(phys_addr_t) * 2 + 2; size = sizeof(phys_addr_t);
break; break;
} }
return number(buf, end, num, spec); return special_hex_number(buf, end, num, size);
} }
static noinline_for_stack static noinline_for_stack
...@@ -1387,10 +1391,7 @@ char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec, ...@@ -1387,10 +1391,7 @@ char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
#ifdef CONFIG_COMMON_CLK #ifdef CONFIG_COMMON_CLK
return string(buf, end, __clk_get_name(clk), spec); return string(buf, end, __clk_get_name(clk), spec);
#else #else
spec.base = 16; return special_hex_number(buf, end, (unsigned long)clk, sizeof(unsigned long));
spec.field_width = sizeof(unsigned long) * 2 + 2;
spec.flags |= SPECIAL | SMALL | ZEROPAD;
return number(buf, end, (unsigned long)clk, spec);
#endif #endif
} }
} }
...@@ -1622,11 +1623,11 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, ...@@ -1622,11 +1623,11 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
case 'N': case 'N':
switch (fmt[1]) { switch (fmt[1]) {
case 'F': case 'F':
return netdev_feature_string(buf, end, ptr, spec); return netdev_feature_string(buf, end, ptr);
} }
break; break;
case 'a': case 'a':
return address_val(buf, end, ptr, spec, fmt); return address_val(buf, end, ptr, fmt);
case 'd': case 'd':
return dentry_name(buf, end, ptr, spec, fmt); return dentry_name(buf, end, ptr, spec, fmt);
case 'C': case 'C':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment