mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] s390/dis: Mark non-NUL-terminated character arrays with __nonstring
@ 2026-10-05  9:22 Heiko Carstens
  2026-10-05 11:21 ` Jens Remus
  0 siblings, 1 reply; 2+ messages in thread
From: Heiko Carstens @ 2026-10-05  9:22 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>
---

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


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

* Re: [PATCH v2] s390/dis: Mark non-NUL-terminated character arrays with __nonstring
  2026-10-05  9:22 [PATCH v2] s390/dis: Mark non-NUL-terminated character arrays with __nonstring Heiko Carstens
@ 2026-10-05 11:21 ` Jens Remus
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Remus @ 2026-10-05 11:21 UTC (permalink / raw)
  To: Heiko Carstens, Alexander Gordeev, Sven Schnelle, Vasily Gorbik,
	Christian Borntraeger
  Cc: linux-kernel, linux-s390

On 10/5/2026 11:22 AM, Heiko Carstens wrote:
> 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>

Reviewed-by: Jens Remus <jremus@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(-)

Regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
jremus@de.ibm.com / jremus@linux.ibm.com

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/


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

end of thread, other threads:[~2026-10-05 11:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-05  9:22 [PATCH v2] s390/dis: Mark non-NUL-terminated character arrays with __nonstring Heiko Carstens
2026-10-05 11:21 ` Jens Remus

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®