Skip to contentSkip to conversation

wifi: mwifiex: Add __nonstring annotations for unterminated strings

PATCH In review Kees Cook 2 participants 2 messages Mar 10, 2025 – Mar 25, 2025 Marvell mwifiex wireless driver

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 wifi: mwifiex: 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.

Cc Brian Norris <[email protected]>
Cc Francesco Dolcini <[email protected]>
Cc Johannes Berg <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Allison Randal <[email protected]>
---
 drivers/net/wireless/marvell/mwifiex/cfp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/mwifiex/cfp.c +1 -1
index d39092b99212..d7fd79214bcf 100644
@@ -150,7 +150,7 @@ static const u16 ac_mcs_rate_nss2[8][10] = {
 
 struct region_code_mapping {
 	u8 code;
-	u8 region[IEEE80211_COUNTRY_STRING_LEN];
+	u8 region[IEEE80211_COUNTRY_STRING_LEN] __nonstring;
 };
 
 static struct region_code_mapping region_code_mapping_t[] = {
Signature · 1 line
2.34.1
maintainer Acked-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 9 lines
Cc Brian Norris <[email protected]>
Cc Francesco Dolcini <[email protected]>
Cc Johannes Berg <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Allison Randal <[email protected]>

This code is kinda weird, because only 2 bytes actually end up used, and yet we explicitly initialize it with 3 non-NUL bytes.

This solutions seems fine though, as it is indeed not a C string and does not desire nor rely on a NUL byte:

Looks like Johannes already applied it anyway.