public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL
@ 2018-02-16 19:28 Andy Shevchenko
  2018-02-16 19:28 ` [PATCH v1 2/7] lib/vsprintf: Deduplicate pointer_string() Andy Shevchenko
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 19:28 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton
  Cc: Andy Shevchenko

Sparse complains that constant is so bit for unsigned long on 64-bit
architecture.

lib/test_printf.c:217:54: warning: constant 0xffff0123456789ab is so big it is unsigned long
lib/test_printf.c:246:54: warning: constant 0xffff0123456789ab is so big it is unsigned long

To satisfy everyone, mark the constant with ULL.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/test_printf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/test_printf.c b/lib/test_printf.c
index 71ebfa43ad05..309cf8d7e6d4 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -204,7 +204,7 @@ test_string(void)
 #if BITS_PER_LONG == 64
 
 #define PTR_WIDTH 16
-#define PTR ((void *)0xffff0123456789ab)
+#define PTR ((void *)0xffff0123456789abULL)
 #define PTR_STR "ffff0123456789ab"
 #define ZEROS "00000000"	/* hex 32 zero bits */
 
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 2/7] lib/vsprintf: Deduplicate pointer_string()
  2018-02-16 19:28 [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko
@ 2018-02-16 19:28 ` Andy Shevchenko
  2018-02-16 19:28 ` [PATCH v1 3/7] lib/vsprintf: Replace ' ' with '_' before crng is ready Andy Shevchenko
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 19:28 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton
  Cc: Andy Shevchenko

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>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/vsprintf.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d7a708f82559..b6d254723828 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1697,10 +1697,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);
 	}
@@ -1715,15 +1714,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);
 }
 
 /*
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 3/7] lib/vsprintf: Replace ' ' with '_' before crng is ready
  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
  2018-02-16 19:28 ` [PATCH v1 4/7] lib/vsprintf: Remove useless NULL checks Andy Shevchenko
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 19:28 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton
  Cc: Shunyong Yang, Joey Zheng, Andy Shevchenko

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 4/7] lib/vsprintf: Remove useless NULL checks
  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 ` [PATCH v1 3/7] lib/vsprintf: Replace ' ' with '_' before crng is ready Andy Shevchenko
@ 2018-02-16 19:28 ` Andy Shevchenko
  2018-02-16 19:28 ` [PATCH v1 5/7] lib/vsprintf: Make decspec global Andy Shevchenko
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 19:28 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton
  Cc: Andy Shevchenko

The pointer can't be NULL since it's first what has been done in the
pointer().

Remove useless checks.

Note we leave check for !CONFIG_HAVE_CLK to make compiler
to optimize code away when possible.

Cc: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/vsprintf.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 360e751305bf..79f27ebdeb6e 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -813,10 +813,6 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
 		/* nothing to print */
 		return buf;
 
-	if (ZERO_OR_NULL_PTR(addr))
-		/* NULL pointer */
-		return string(buf, end, NULL, spec);
-
 	switch (fmt[1]) {
 	case 'C':
 		separator = ':';
@@ -1255,10 +1251,6 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
 	if (spec.field_width == 0)
 		return buf;				/* nothing to print */
 
-	if (ZERO_OR_NULL_PTR(addr))
-		return string(buf, end, NULL, spec);	/* NULL pointer */
-
-
 	do {
 		switch (fmt[count++]) {
 		case 'a':
@@ -1442,7 +1434,7 @@ static noinline_for_stack
 char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
 	    const char *fmt)
 {
-	if (!IS_ENABLED(CONFIG_HAVE_CLK) || !clk)
+	if (!IS_ENABLED(CONFIG_HAVE_CLK))
 		return string(buf, end, NULL, spec);
 
 	switch (fmt[1]) {
@@ -1581,9 +1573,6 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
 	if (!IS_ENABLED(CONFIG_OF))
 		return string(buf, end, "(!OF)", spec);
 
-	if ((unsigned long)dn < PAGE_SIZE)
-		return string(buf, end, "(null)", spec);
-
 	/* simple case without anything any more format specifiers */
 	fmt++;
 	if (fmt[0] == '\0' || strcspn(fmt,"fnpPFcC") > 0)
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 5/7] lib/vsprintf: Make decspec global
  2018-02-16 19:28 [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko
                   ` (2 preceding siblings ...)
  2018-02-16 19:28 ` [PATCH v1 4/7] lib/vsprintf: Remove useless NULL checks Andy Shevchenko
@ 2018-02-16 19:28 ` Andy Shevchenko
  2018-02-16 19:28 ` [PATCH v1 6/7] lib/vsprintf: Make strspec global Andy Shevchenko
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 19:28 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton
  Cc: Andy Shevchenko

There are places where default specification to print decimal numbers
is in use.

Make it global and convert existing users.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/vsprintf.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 79f27ebdeb6e..3a02fcaf8ac8 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -693,6 +693,11 @@ char *symbol_string(char *buf, char *end, void *ptr,
 #endif
 }
 
+static const struct printf_spec default_dec_spec = {
+	.base = 10,
+	.precision = -1,
+};
+
 static noinline_for_stack
 char *resource_string(char *buf, char *end, struct resource *res,
 		      struct printf_spec spec, const char *fmt)
@@ -722,11 +727,6 @@ char *resource_string(char *buf, char *end, struct resource *res,
 		.precision = -1,
 		.flags = SMALL | ZEROPAD,
 	};
-	static const struct printf_spec dec_spec = {
-		.base = 10,
-		.precision = -1,
-		.flags = 0,
-	};
 	static const struct printf_spec str_spec = {
 		.field_width = -1,
 		.precision = 10,
@@ -760,10 +760,10 @@ char *resource_string(char *buf, char *end, struct resource *res,
 		specp = &mem_spec;
 	} else if (res->flags & IORESOURCE_IRQ) {
 		p = string(p, pend, "irq ", str_spec);
-		specp = &dec_spec;
+		specp = &default_dec_spec;
 	} else if (res->flags & IORESOURCE_DMA) {
 		p = string(p, pend, "dma ", str_spec);
-		specp = &dec_spec;
+		specp = &default_dec_spec;
 	} else if (res->flags & IORESOURCE_BUS) {
 		p = string(p, pend, "bus ", str_spec);
 		specp = &bus_spec;
@@ -899,9 +899,6 @@ char *bitmap_list_string(char *buf, char *end, unsigned long *bitmap,
 	int cur, rbot, rtop;
 	bool first = true;
 
-	/* reused to print numbers */
-	spec = (struct printf_spec){ .base = 10 };
-
 	rbot = cur = find_first_bit(bitmap, nr_bits);
 	while (cur < nr_bits) {
 		rtop = cur;
@@ -916,13 +913,13 @@ char *bitmap_list_string(char *buf, char *end, unsigned long *bitmap,
 		}
 		first = false;
 
-		buf = number(buf, end, rbot, spec);
+		buf = number(buf, end, rbot, default_dec_spec);
 		if (rbot < rtop) {
 			if (buf < end)
 				*buf = '-';
 			buf++;
 
-			buf = number(buf, end, rtop, spec);
+			buf = number(buf, end, rtop, default_dec_spec);
 		}
 
 		rbot = cur;
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 6/7] lib/vsprintf: Make strspec global
  2018-02-16 19:28 [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko
                   ` (3 preceding siblings ...)
  2018-02-16 19:28 ` [PATCH v1 5/7] lib/vsprintf: Make decspec global Andy Shevchenko
@ 2018-02-16 19:28 ` 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
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 19:28 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton
  Cc: Andy Shevchenko

There is at least one new user is coming where default specification to print
strings is in use.

Make it global.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/vsprintf.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3a02fcaf8ac8..20c0ab9faba5 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -693,6 +693,11 @@ char *symbol_string(char *buf, char *end, void *ptr,
 #endif
 }
 
+static const struct printf_spec default_str_spec = {
+	.field_width = -1,
+	.precision = -1,
+};
+
 static const struct printf_spec default_dec_spec = {
 	.base = 10,
 	.precision = -1,
@@ -1453,10 +1458,6 @@ char *format_flags(char *buf, char *end, unsigned long flags,
 					const struct trace_print_flags *names)
 {
 	unsigned long mask;
-	const struct printf_spec strspec = {
-		.field_width = -1,
-		.precision = -1,
-	};
 	const struct printf_spec numspec = {
 		.flags = SPECIAL|SMALL,
 		.field_width = -1,
@@ -1469,7 +1470,7 @@ char *format_flags(char *buf, char *end, unsigned long flags,
 		if ((flags & mask) != mask)
 			continue;
 
-		buf = string(buf, end, names->name, strspec);
+		buf = string(buf, end, names->name, default_str_spec);
 
 		flags &= ~mask;
 		if (flags) {
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 7/7] lib/vsprintf: Mark expected switch fall-through
  2018-02-16 19:28 [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko
                   ` (4 preceding siblings ...)
  2018-02-16 19:28 ` [PATCH v1 6/7] lib/vsprintf: Make strspec global Andy Shevchenko
@ 2018-02-16 19:28 ` Andy Shevchenko
  2018-02-16 20:44 ` [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 19:28 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton
  Cc: Andy Shevchenko

In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/vsprintf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 20c0ab9faba5..bf0c45788100 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2094,6 +2094,7 @@ int format_decode(const char *fmt, struct printf_spec *spec)
 
 	case 'x':
 		spec->flags |= SMALL;
+		/* fall through */
 
 	case 'X':
 		spec->base = 16;
@@ -3048,8 +3049,10 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
 			break;
 		case 'i':
 			base = 0;
+			/* fall through */
 		case 'd':
 			is_sign = true;
+			/* fall through */
 		case 'u':
 			break;
 		case '%':
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL
  2018-02-16 19:28 [PATCH v1 1/7] lib/test_printf: Mark big constant with ULL Andy Shevchenko
                   ` (5 preceding siblings ...)
  2018-02-16 19:28 ` [PATCH v1 7/7] lib/vsprintf: Mark expected switch fall-through Andy Shevchenko
@ 2018-02-16 20:44 ` Andy Shevchenko
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-02-16 20:44 UTC (permalink / raw)
  To: Tobin C. Harding, linux, Petr Mladek, Joe Perches, linux-kernel,
	Andrew Morton

On Fri, 2018-02-16 at 21:28 +0200, Andy Shevchenko wrote:
> Sparse complains that constant is so bit for unsigned long on 64-bit
> architecture.
> 
> lib/test_printf.c:217:54: warning: constant 0xffff0123456789ab is so
> big it is unsigned long
> lib/test_printf.c:246:54: warning: constant 0xffff0123456789ab is so
> big it is unsigned long
> 
> To satisfy everyone, mark the constant with ULL.
> 

Please, drop entire series.

I found more candidates inside the file which can utilize changes.
Besides that, there is a typo in commit message of patch 3.



> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  lib/test_printf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/test_printf.c b/lib/test_printf.c
> index 71ebfa43ad05..309cf8d7e6d4 100644
> --- a/lib/test_printf.c
> +++ b/lib/test_printf.c
> @@ -204,7 +204,7 @@ test_string(void)
>  #if BITS_PER_LONG == 64
>  
>  #define PTR_WIDTH 16
> -#define PTR ((void *)0xffff0123456789ab)
> +#define PTR ((void *)0xffff0123456789abULL)
>  #define PTR_STR "ffff0123456789ab"
>  #define ZEROS "00000000"	/* hex 32 zero bits */
>  

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-02-16 20:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v1 3/7] lib/vsprintf: Replace ' ' with '_' before crng is ready Andy Shevchenko
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox