diff options
author | Shunyong Yang <shunyong.yang@hxt-semitech.com> | 2018-02-16 16:07:09 -0500 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2018-04-11 05:18:43 -0400 |
commit | 91efafb1dd8f471177a3dddb4841d75d3df1cc46 (patch) | |
tree | 87923e6f1ea1c0b8163a0ac710c85432a41ba029 | |
parent | 496a9a5f3806d58b14ae06b390d5b1ffa26e9f9a (diff) |
lib/vsprintf: Replace space with '_' before crng is ready
Before crng is ready, output of "%p" composes of "(ptrval)" and
left padding spaces for alignment as no random address can be
generated. This seems a little strange when default string width
is larger than strlen("(ptrval)").
For example, when irq domain names are built with "%p", the nodes
under /sys/kernel/debug/irq/domains like this on AArch64 system,
[root@y irq]# ls domains/
default irqchip@ (ptrval)-2
irqchip@ (ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3
irqchip@ (ptrval) irqchip@ (ptrval)-3
\_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2
The name "irqchip@ (ptrval)-2" is not so readable in console
output.
This patch replaces space with readable "_" when output needs padding.
Following is the output after applying the patch,
[root@y domains]# ls
default irqchip@(____ptrval____)-2
irqchip@(____ptrval____)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3
irqchip@(____ptrval____) irqchip@(____ptrval____)-3 \_SB_.TCS0.QIC0
\_SB_.TCS0.QIC2
There is same problem in some subsystem's dmesg output. Moreover,
someone may call "%p" in a similar case. In addition, the timing of
crng initialization done may vary on different system. So, the change
is made in vsprintf.c.
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Link: http://lkml.kernel.org/r/20180216210711.79901-7-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>
Cc: Joey Zheng <yu.zheng@hxt-semitech.com>
Signed-off-by: Shunyong Yang <shunyong.yang@hxt-semitech.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
-rw-r--r-- | lib/vsprintf.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 9004bbb3d84d..97be2d07297a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -1681,12 +1681,13 @@ early_initcall(initialize_ptr_random); | |||
1681 | /* Maps a pointer to a 32 bit unique identifier. */ | 1681 | /* Maps a pointer to a 32 bit unique identifier. */ |
1682 | static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) | 1682 | static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) |
1683 | { | 1683 | { |
1684 | const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)"; | ||
1684 | unsigned long hashval; | 1685 | unsigned long hashval; |
1685 | 1686 | ||
1686 | if (unlikely(!have_filled_random_ptr_key)) { | 1687 | if (unlikely(!have_filled_random_ptr_key)) { |
1687 | spec.field_width = 2 * sizeof(ptr); | 1688 | spec.field_width = 2 * sizeof(ptr); |
1688 | /* string length must be less than default_width */ | 1689 | /* string length must be less than default_width */ |
1689 | return string(buf, end, "(ptrval)", spec); | 1690 | return string(buf, end, str, spec); |
1690 | } | 1691 | } |
1691 | 1692 | ||
1692 | #ifdef CONFIG_64BIT | 1693 | #ifdef CONFIG_64BIT |