LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] sparc: mdesc: Fix compile error seen with gcc 11.x
@ 2021-09-14 22:47 Guenter Roeck
  2021-09-15  8:38 ` David Laight
  2021-09-15 14:04 ` Arnd Bergmann
  0 siblings, 2 replies; 3+ messages in thread
From: Guenter Roeck @ 2021-09-14 22:47 UTC (permalink / raw)
  To: David S . Miller
  Cc: sparclinux, linux-kernel, Guenter Roeck, Arnd Bergmann,
	David Laight, Anatoly Pugachev, Sam Ravnborg

sparc64 images fail to compile with gcc 11.x, reporting the following
errors.

arch/sparc/kernel/mdesc.c:647:22: error:
	'strcmp' reading 1 or more bytes from a region of size 0
arch/sparc/kernel/mdesc.c:692:22: error:
	'strcmp' reading 1 or more bytes from a region of size 0
arch/sparc/kernel/mdesc.c:719:21:
	error: 'strcmp' reading 1 or more bytes from a region of size 0

The underlying problem is that node_block() returns a pointer beyond
the end of struct mdesc_hdr. gcc 11.x detects that and reports the error.
Adding an additional zero-length field to struct mdesc_hdr and pointing
to that field fixes the problem.

Cc: Arnd Bergmann <arnd@kernel.org>
Cc: David Laight <David.Laight@ACULAB.COM>
Cc: Anatoly Pugachev <matorola@gmail.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: data[0] => data[]

I am not sure if there was agreement to accept this patch or not, but
I was asked to resend it with the above change, so here it is. An open
question was if it is acceptable to have a structure named xxx_hdr
include an element pointing to the data following that header.

If this patch is not acceptable, the patch in buildbot may be a possible
alternative to consider.
    https://git.busybox.net/buildroot/commit/?id=6e1106b4a9aee25d1556310d5cd1cb6dde2e6e3f

 arch/sparc/kernel/mdesc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/mdesc.c b/arch/sparc/kernel/mdesc.c
index 8e645ddac58e..83e1f699bc32 100644
--- a/arch/sparc/kernel/mdesc.c
+++ b/arch/sparc/kernel/mdesc.c
@@ -39,6 +39,7 @@ struct mdesc_hdr {
 	u32	node_sz; /* node block size */
 	u32	name_sz; /* name block size */
 	u32	data_sz; /* data block size */
+	char	data[];
 } __attribute__((aligned(16)));
 
 struct mdesc_elem {
@@ -612,7 +613,7 @@ EXPORT_SYMBOL(mdesc_get_node_info);
 
 static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
 {
-	return (struct mdesc_elem *) (mdesc + 1);
+	return (struct mdesc_elem *) (mdesc->data);
 }
 
 static void *name_block(struct mdesc_hdr *mdesc)
-- 
2.33.0


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

end of thread, other threads:[~2021-09-15 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 22:47 [PATCH v2] sparc: mdesc: Fix compile error seen with gcc 11.x Guenter Roeck
2021-09-15  8:38 ` David Laight
2021-09-15 14:04 ` 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).