All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Carstens <hca@linux.ibm.com>
To: Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Jens Remus <jremus@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH v2] s390/dis: Mark non-NUL-terminated character arrays with __nonstring
Date: Mon,  5 Oct 2026 11:22:56 +0200	[thread overview]
Message-ID: <20261005092256.2740363-1-hca@linux.ibm.com> (raw)

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>
---

Notes:
    Use __nonstring_array for long_insn_name array, since compilers before
    gcc 15 will otherwise warn with:
    
    arch/s390/kernel/dis.c:343:1: warning: 'nonstring' attribute ignored
     on objects of type 'char[][7]' [-Wattributes]

 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..9c349eb884bf 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_array = 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


             reply	other threads:[~2026-10-05  9:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05  9:22 Heiko Carstens [this message]
2026-10-05  9:27 ` [PATCH v2] s390/dis: Mark non-NUL-terminated character arrays with __nonstring sashiko-bot
2026-10-05 11:21 ` Jens Remus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261005092256.2740363-1-hca@linux.ibm.com \
    --to=hca@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=jremus@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.