emulex/benet: Annotate flash_cookie as nonstring
Subsystems (3)
PATCH 1/1 emulex/benet: Annotate flash_cookie as nonstring
GCC 15's new -Wunterminated-string-initialization notices that the 32 character "flash_cookie" (which is not used as a C-String) needs to be marked as "nonstring":
drivers/net/ethernet/emulex/benet/be_cmds.c:2618:51: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]
2618 | static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "};
| ^~~~~~~~~~~~~~~~~~Add this annotation, avoid using a multidimensional array, but keep the string split (with a comment about why). Additionally mark it const and annotate the "cookie" member that is being memcmp()ed against as nonstring too.
---
Cc: Ajit Khaparde <[email protected]>
Cc: Sriharsha Basavapatna <[email protected]>
Cc: Somnath Kotur <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: [email protected]
--- drivers/net/ethernet/emulex/benet/be_cmds.c | 6 +++++- drivers/net/ethernet/emulex/benet/be_cmds.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/emulex/benet/be_cmds.c +5 -1
@@ -2615,7 +2615,11 @@ static int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,return status; } -static char flash_cookie[2 ][16 ] = {"*** SE FLAS" ,"H DIRECTORY *** " }; +/* +* Since the cookie is text, add a parsing-skipped space to keep it from +* ever being matched on storage holding this source file. +*/ +static const char flash_cookie[32] __nonstring = "*** SE FLAS" "H DIRECTORY *** ";static bool phy_flashing_required (struct be_adapter *adapter) {
drivers/net/ethernet/emulex/benet/be_cmds.h +1 -1
@@ -1415,7 +1415,7 @@ struct flash_section_entry { } __packed;struct flash_section_info { -u8 cookie[32 ]; + u8 cookie[32] __nonstring;struct flash_section_hdr fsec_hdr;struct flash_section_entry fsec_entry[32 ]; } __packed;
Signature · 1 line
2.34.1
Quoted 8 lines · Kees Cook
GCC 15's new -Wunterminated-string-initialization notices that the 32 character "
flash_cookie" (which is not used as a C-String) needs to be marked as "nonstring":
drivers/net/ethernet/emulex/benet/be_cmds.c:2618:51: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]2618 | static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "}; | ^~~~~~~~~~~~~~~~~~
Quoted 6 lines
Add this annotation, avoid using a multidimensional array, but keep the string split (with a comment about why). Additionally mark it const and annotate the "cookie" member that is being memcmp()ed against as nonstring too.
Signed-off-by Kees Cook <[email protected]>
I am assuming this is for net-next.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 16 Apr 2025 15:10:29 -0700 you wrote:
GCC 15's new -Wunterminated-string-initialization notices that the 32 character "
flash_cookie" (which is not used as a C-String) needs to be marked as "nonstring":
drivers/net/ethernet/emulex/benet/be_cmds.c:2618:51: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]2618 | static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "}; | ^~~~~~~~~~~~~~~~~~[...]
Here is the summary with links:
- emulex/benet: Annotate flash_cookie as nonstring
https://git.kernel.org/netdev/net-next/c/f0f149d9747f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html