All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparc: mdesc: Fix compile error seen with gcc 11.x
@ 2021-09-13 16:37 Guenter Roeck
       [not found] ` <YT+SPIAl0IdWOAn/@ravnborg.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2021-09-13 16:37 UTC (permalink / raw)
  To: David S . Miller; +Cc: sparclinux, linux-kernel, Guenter Roeck, Arnd Bergmann

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>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
My apologies if a similar patch was submitted already; I was unable to find it.
I did find the following patch:
    https://git.busybox.net/buildroot/commit/?id=6e1106b4a9aee25d1556310d5cd1cb6dde2e6e3f
but I failed to find it in patchwork or on lore.kernel.org, and it
seems to be more expensive than the solution suggested here.

 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..c67bdcc23727 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[0];
 } __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 related	[flat|nested] 8+ messages in thread

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13 16:37 [PATCH] sparc: mdesc: Fix compile error seen with gcc 11.x Guenter Roeck
     [not found] ` <YT+SPIAl0IdWOAn/@ravnborg.org>
2021-09-13 18:52   ` Guenter Roeck
2021-09-14 12:02     ` Anatoly Pugachev
2021-09-14 14:17     ` David Laight
2021-09-14 14:24       ` Guenter Roeck
2021-09-14 14:53         ` Arnd Bergmann
2021-09-14 15:03           ` David Laight
2021-09-14 15:17             ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.