Skip to contentSkip to conversation

md/bcache: Mark __nonstring look-up table

PATCH In review Kees Cook 2 participants 5 messages Apr 18, 2025 – May 8, 2025 bcache (block layer cache)

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 1/1 md/bcache: Mark __nonstring look-up table

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

  549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation (since it is not used as a C-String), and switch the initializer to an array of bytes.

---
v2: use byte array initializer (colyli)
v1: https://lore.kernel.org/all/[email protected]/
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]

---
 drivers/md/bcache/super.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/bcache/super.c +2 -1
index e42f1400cea9..a76ce92502ed 100644
@@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-	static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+	static const char zero_uuid[] __nonstring =
+		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 	return uuid_find(c, zero_uuid);
 }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 33 lines

2025年4月19日 04:21,Kees Cook <[email protected]> 写道:

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

 549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
     |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation (since it is not used as a C-String), and switch the initializer to an array of bytes.

---
v2: use byte array initializer (colyli)
v1: https://lore.kernel.org/all/[email protected]/
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]
---
drivers/md/bcache/super.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..a76ce92502ed 100644

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 549

Quoted 5 lines
drivers/md/bcache/super.c +1 -1
@@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
- static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ static const char zero_uuid[] __nonstring =

I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.

Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?

Thanks.

Coly Li

Quoted 8 lines
drivers/md/bcache/super.c +1 -0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 return uuid_find(c, zero_uuid);
 }
Signature · 1 line
2.34.1
#2 lore raw
Quoted 38 lines
Quoted 32 lines · 2025年4月19日 11:55,Coly Li <[email protected]> 写道:

2025年4月19日 04:21,Kees Cook <[email protected]> 写道:

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
    |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation (since it is not used as a C-String), and switch the initializer to an array of bytes.

---
v2: use byte array initializer (colyli)
v1: https://lore.kernel.org/all/[email protected]/
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]
---
drivers/md/bcache/super.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..a76ce92502ed 100644
@@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
Quoted 5 lines

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 549

Quoted 4 lines
drivers/md/bcache/super.c +1 -1
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
- static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ static const char zero_uuid[] __nonstring =

Hi Kees,

Quoted 3 lines

I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.

Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?

Ping ?

You are expert here, I need your opinion.

Thanks.

Coly Li

Quoted 6 lines
Quoted 6 lines
drivers/md/bcache/super.c +1 -0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 return uuid_find(c, zero_uuid);
 }
Signature · 1 line
2.34.1
author
#3 lore raw
Quoted 37 lines · Coly Li
Quoted 37 lines
Quoted 32 lines · 2025年4月19日 11:55,Coly Li <[email protected]> 写道:

2025年4月19日 04:21,Kees Cook <[email protected]> 写道:

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
    |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation (since it is not used as a C-String), and switch the initializer to an array of bytes.

---
v2: use byte array initializer (colyli)
v1: https://lore.kernel.org/all/[email protected]/
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]
---
drivers/md/bcache/super.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..a76ce92502ed 100644
@@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
Quoted 11 lines
Quoted 5 lines

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 549

Quoted 4 lines
drivers/md/bcache/super.c +1 -1
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
- static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ static const char zero_uuid[] __nonstring =

Hi Kees,

Quoted 3 lines

I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.

Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?

Either way is fine. I can update the patch to use the "[16]" again if you'd like?

-Kees

Quoted 18 lines

Ping ?

You are expert here, I need your opinion.

Thanks.

Coly Li

Quoted 6 lines
Quoted 6 lines
drivers/md/bcache/super.c +1 -0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 return uuid_find(c, zero_uuid);
 }
Signature · 1 line
2.34.1
Signature · 1 line
Kees Cook
#4 lore raw
Quoted 48 lines

2025年5月8日 23:58,Kees Cook <[email protected]> 写道:

Quoted 43 lines · Coly Li
Quoted 42 lines
Quoted 36 lines · 2025年4月19日 11:55,Coly Li <[email protected]> 写道:

2025年4月19日 04:21,Kees Cook <[email protected]> 写道:

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
   |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation (since it is not used as a C-String), and switch the initializer to an array of bytes.

---
v2: use byte array initializer (colyli)
v1: https://lore.kernel.org/all/[email protected]/
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]
---
drivers/md/bcache/super.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index e42f1400cea9..a76ce92502ed 100644
@@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
- static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ static const char zero_uuid[] __nonstring =
Quoted 9 lines
Quoted 5 lines

Hi Kees,

Quoted 3 lines

I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.

Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?

Either way is fine. I can update the patch to use the "[16]" again if you'd like?

Yes please. Thanks in advance.

Coly Li

Quoted 22 lines
Quoted 19 lines

Ping ?

You are expert here, I need your opinion.

Thanks.

Coly Li

Quoted 6 lines
Quoted 6 lines
drivers/md/bcache/super.c +1 -0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 return uuid_find(c, zero_uuid);
 }
Signature · 1 line
2.34.1
Signature · 1 line
Kees Cook