public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Tobin C. Harding" <me@tobin.cc>,
	linux@rasmusvillemoes.dk, Petr Mladek <pmladek@suse.com>,
	Joe Perches <joe@perches.com>,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Shunyong Yang <shunyong.yang@hxt-semitech.com>,
	Joey Zheng <yu.zheng@hxt-semitech.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 3/7] lib/vsprintf: Replace ' ' with '_' before crng is ready
Date: Fri, 16 Feb 2018 21:28:02 +0200	[thread overview]
Message-ID: <20180216192806.68914-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20180216192806.68914-1-andriy.shevchenko@linux.intel.com>

From: Shunyong Yang <shunyong.yang@hxt-semitech.com>

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.

Cc: Joey Zheng <yu.zheng@hxt-semitech.com>
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Shunyong Yang <shunyong.yang@hxt-semitech.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/vsprintf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b6d254723828..360e751305bf 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1696,12 +1696,13 @@ early_initcall(initialize_ptr_random);
 /* Maps a pointer to a 32 bit unique identifier. */
 static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
 {
+	const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)";
 	unsigned long hashval;
 
 	if (unlikely(!have_filled_random_ptr_key)) {
 		spec.field_width = 2 * sizeof(ptr);
 		/* string length must be less than default_width */
-		return string(buf, end, "(ptrval)", spec);
+		return string(buf, end, str, spec);
 	}
 
 #ifdef CONFIG_64BIT
-- 
2.15.1

  parent reply	other threads:[~2018-02-16 19:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-16 19:28 [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko
2018-02-16 19:28 ` [PATCH v1 2/7] lib/vsprintf: Deduplicate pointer_string() Andy Shevchenko
2018-02-16 19:28 ` Andy Shevchenko [this message]
2018-02-16 19:28 ` [PATCH v1 4/7] lib/vsprintf: Remove useless NULL checks Andy Shevchenko
2018-02-16 19:28 ` [PATCH v1 5/7] lib/vsprintf: Make decspec global Andy Shevchenko
2018-02-16 19:28 ` [PATCH v1 6/7] lib/vsprintf: Make strspec global Andy Shevchenko
2018-02-16 19:28 ` [PATCH v1 7/7] lib/vsprintf: Mark expected switch fall-through Andy Shevchenko
2018-02-16 20:44 ` [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180216192806.68914-3-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=me@tobin.cc \
    --cc=pmladek@suse.com \
    --cc=shunyong.yang@hxt-semitech.com \
    --cc=yu.zheng@hxt-semitech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox