Skip to contentSkip to conversation

iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings

PATCH In review Kees Cook 3 participants 5 messages Mar 10, 2025 – Apr 22, 2025

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 iio: magnetometer: ak8974: Add __nonstring annotations for unterminated strings

When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with __nonstring to and correctly identify the char array as "not a C string" and thereby eliminate the warning.

---
 drivers/iio/magnetometer/ak8974.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/ak8974.c +2 -2
index 08975c60e325..44d8428a69b0 100644
@@ -535,8 +535,8 @@ static int ak8974_detect(struct ak8974 *ak8974)
 				       fab_data2, sizeof(fab_data2));
 
 		for (i = 0; i < 3; ++i) {
-			static const char axis[3] = "XYZ";
-			static const char pgaxis[6] = "ZYZXYX";
+			static const char axis[3] __nonstring = "XYZ";
+			static const char pgaxis[6] __nonstring = "ZYZXYX";
 			unsigned offz = le16_to_cpu(fab_data2[i]) & 0x7F;
 			unsigned fine = le16_to_cpu(fab_data1[i]);
 			unsigned sens = le16_to_cpu(fab_data1[i + 3]);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Kees Cook

When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with __nonstring to and correctly identify the char array as "not a C string" and thereby eliminate the warning.

Quoted 6 lines

Fair enough,

Yours,
Linus Walleij

maintainer
#2 lore raw
Quoted 15 lines · On Fri, 14 Mar 2025 11:31:09 +0100 Linus Walleij <[email protected]>…
Quoted 6 lines · Kees Cook

When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with __nonstring to and correctly identify the char array as "not a C string" and thereby eliminate the warning.

Quoted 6 lines
Quoted 3 lines

Fair enough,

Kees,

I've currently queued this for next cycle as it doesn't feel like a fix as such and I've already sent my pull request for the merge window.

Is it worth rushing it in, or is a fully cycle delay an issue? (6.16)

If slow is fine, applied to the testing branch of iio.git which gets 0-day bot exposure.

Jonathan

Quoted 2 lines

Yours,
Linus Walleij

author
#3 lore raw
Quoted 23 lines · Jonathan Cameron
Quoted 15 lines · On Fri, 14 Mar 2025 11:31:09 +0100 Linus Walleij <[email protected]>…
Quoted 6 lines · Kees Cook

When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with __nonstring to and correctly identify the char array as "not a C string" and thereby eliminate the warning.

Quoted 6 lines
Quoted 3 lines

Fair enough,

Kees,

Quoted 7 lines

I've currently queued this for next cycle as it doesn't feel like a fix as such and I've already sent my pull request for the merge window.

Is it worth rushing it in, or is a fully cycle delay an issue? (6.16)

If slow is fine, applied to the testing branch of iio.git which gets 0-day bot exposure.

No rush needed at all. This is just for cleaning up warnings for the coming releases of GCC 15 in couple months. Thanks for picking it up!

Signature · 1 line
Kees Cook
maintainer
#4 lore raw
Quoted 27 lines · On Sat, 15 Mar 2025 14:56:02 -0700 Kees Cook <[email protected]> wrote:
Quoted 26 lines · Jonathan Cameron
Quoted 15 lines · On Fri, 14 Mar 2025 11:31:09 +0100 Linus Walleij <[email protected]>…
Quoted 6 lines · Kees Cook

When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with __nonstring to and correctly identify the char array as "not a C string" and thereby eliminate the warning.

Quoted 6 lines
Quoted 3 lines

Fair enough,

Kees,

I've currently queued this for next cycle as it doesn't feel like a fix as such and I've already sent my pull request for the merge window.

Quoted 8 lines
Quoted 4 lines

Is it worth rushing it in, or is a fully cycle delay an issue? (6.16)

If slow is fine, applied to the testing branch of iio.git which gets 0-day bot exposure.

No rush needed at all. This is just for cleaning up warnings for the coming releases of GCC 15 in couple months. Thanks for picking it up!

Dropped because it clashes with:

05e8d261a34e ("gcc-15: add '__nonstring' markers to byte arrays")