mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] s390/dis: Mark non-NUL-terminated character arrays with __nonstring
@ 2026-10-02 10:44 Heiko Carstens
  0 siblings, 0 replies; only message in thread
From: Heiko Carstens @ 2026-10-02 10:44 UTC (permalink / raw)
  To: Alexander Gordeev, Sven Schnelle, Vasily Gorbik,
	Christian Borntraeger, Jens Remus
  Cc: linux-kernel, linux-s390

With [1] the generated string initializers were changed to use an
array instead of a non-NUL-terminated string. The reason was that GCC 15
warns about string initializers that truncate the NUL terminator with
-Wunterminated-string-initialization.

The better solution is to use the __nonstring annotation, which exists
to deal exactly with this problem. Therefore use it and basically
revert [1] in order to generate more readable initializers:

Before:
[LONG_INSN_ALGHSIK] = { 'a', 'l', 'g', 'h', 's', 'i', 'k', },

After:
[LONG_INSN_ALGHSIK] = "alghsik",

[1] commit 7cbae7ea3de5 ("s390/tools: Use array instead of string initializer")

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/kernel/dis.c             |  4 ++--
 arch/s390/tools/gen_opcode_table.c | 23 ++++-------------------
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/arch/s390/kernel/dis.c b/arch/s390/kernel/dis.c
index 1cec93895b3a..556fe3956c7f 100644
--- a/arch/s390/kernel/dis.c
+++ b/arch/s390/kernel/dis.c
@@ -51,7 +51,7 @@ struct s390_operand {
 
 struct s390_insn {
 	union {
-		const char name[5];
+		const char name[5] __nonstring;
 		struct {
 			unsigned char zero;
 			unsigned int offset;
@@ -340,7 +340,7 @@ static const unsigned char formats[][6] = {
 	[INSTR_VSI_URDV]     = { V_32, D_20, B_16, U8_8, 0, 0 },
 };
 
-static char long_insn_name[][7] = LONG_INSN_INITIALIZER;
+static char long_insn_name[][7] __nonstring = LONG_INSN_INITIALIZER;
 static struct s390_insn opcode[] = OPCODE_TABLE_INITIALIZER;
 static struct s390_opcode_offset opcode_offset[] = OPCODE_OFFSET_INITIALIZER;
 
diff --git a/arch/s390/tools/gen_opcode_table.c b/arch/s390/tools/gen_opcode_table.c
index 7d76c417f83f..820905eca78a 100644
--- a/arch/s390/tools/gen_opcode_table.c
+++ b/arch/s390/tools/gen_opcode_table.c
@@ -201,17 +201,6 @@ static int cmp_long_insn(const void *a, const void *b)
 	return strcmp(((struct insn *)a)->name, ((struct insn *)b)->name);
 }
 
-static void print_insn_name(const char *name)
-{
-	size_t i, len;
-
-	len = strlen(name);
-	printf("{");
-	for (i = 0; i < len; i++)
-		printf(" \'%c\',", name[i]);
-	printf(" }");
-}
-
 static void print_long_insn(struct gen_opcode *desc)
 {
 	struct insn *insn;
@@ -234,9 +223,7 @@ static void print_long_insn(struct gen_opcode *desc)
 		insn = &desc->insn[i];
 		if (insn->name_len < 6)
 			continue;
-		printf("\t[LONG_INSN_%s] = ", insn->upper);
-		print_insn_name(insn->name);
-		printf(", \\\n");
+		printf("\t[LONG_INSN_%s] = \"%s\", \\\n", insn->upper, insn->name);
 	}
 	printf("}\n\n");
 }
@@ -249,12 +236,10 @@ static void print_opcode(struct insn *insn, int nr)
 	if (insn->type->byte != 0)
 		opcode += 2;
 	printf("\t[%4d] = { .opfrag = 0x%s, .format = INSTR_%s, ", nr, opcode, insn->format);
-	if (insn->name_len < 6) {
-		printf(".name =  ");
-		print_insn_name(insn->name);
-	} else {
+	if (insn->name_len < 6)
+		printf(".name = \"%s\"", insn->name);
+	else
 		printf(".offset = LONG_INSN_%s", insn->upper);
-	}
 	printf(" }, \\\n");
 }
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-02 10:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-02 10:44 [PATCH] s390/dis: Mark non-NUL-terminated character arrays with __nonstring Heiko Carstens

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

all inboxes | Powered by JetHome®