linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kallsyms: work around bogus -Wrestrict warning
@ 2020-01-07 21:40 Arnd Bergmann
  2020-01-07 22:25 ` Andrew Morton
  2020-01-08  1:26 ` Masami Hiramatsu
  0 siblings, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2020-01-07 21:40 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Oleksandr Natalenko, linux-mm, Arnd Bergmann,
	Arnaldo Carvalho de Melo, Will Deacon, Masami Hiramatsu,
	Song Liu, Alexey Dobriyan, Marc Zyngier, Thomas Gleixner,
	linux-kernel

gcc -O3 produces some really odd warnings for this file:

kernel/kallsyms.c: In function 'sprint_symbol':
kernel/kallsyms.c:369:3: error: 'strcpy' source argument is the same as destination [-Werror=restrict]
   strcpy(buffer, name);
   ^~~~~~~~~~~~~~~~~~~~
kernel/kallsyms.c: In function 'sprint_symbol_no_offset':
kernel/kallsyms.c:369:3: error: 'strcpy' source argument is the same as destination [-Werror=restrict]
   strcpy(buffer, name);
   ^~~~~~~~~~~~~~~~~~~~
kernel/kallsyms.c: In function 'sprint_backtrace':
kernel/kallsyms.c:369:3: error: 'strcpy' source argument is the same as destination [-Werror=restrict]
   strcpy(buffer, name);
   ^~~~~~~~~~~~~~~~~~~~

This obviously cannot be since it is preceded by an 'if (name != buffer)'
check.

Using sprintf() instead of strcpy() is a bit wasteful but is
the best workaround I could come up with.

Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 kernel/kallsyms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index d812b90f4c86..726b8eeb223e 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -366,7 +366,7 @@ static int __sprint_symbol(char *buffer, unsigned long address,
 		return sprintf(buffer, "0x%lx", address - symbol_offset);
 
 	if (name != buffer)
-		strcpy(buffer, name);
+		sprintf(buffer, "%s", name);
 	len = strlen(buffer);
 	offset -= symbol_offset;
 
-- 
2.20.0


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

end of thread, other threads:[~2020-01-09 22:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-07 21:40 [PATCH] kallsyms: work around bogus -Wrestrict warning Arnd Bergmann
2020-01-07 22:25 ` Andrew Morton
2020-01-08  9:23   ` Oleksandr Natalenko
2020-01-08  1:26 ` Masami Hiramatsu
2020-01-09 22:02   ` Andrew Morton
2020-01-09 22:18     ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).