scsi: pm80xx: Add __nonstring annotations for unterminated strings
Subsystems (2)
PATCH 1/1 scsi: pm80xx: 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/scsi/pm8001/pm8001_ctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/pm8001/pm8001_ctl.c +1 -1
@@ -644,7 +644,7 @@ static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);#define FLASH_CMD_SET_NVMD 0x02struct flash_command { -u8 command[8 ]; + u8 command[8] __nonstring;int code; };
Signature · 1 line
2.34.1
James Bottomley
maintainerQuoted 25 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__nonstringto and correctly identify the char array as "not a C string" and thereby eliminate the warning.Cc Jack Wang <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc "Martin K. Petersen" <[email protected]>Signed-off-by Kees Cook <[email protected]>---
drivers/scsi/pm8001/pm8001_ctl.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/pm8001/pm8001_ctl.c +0
-0@@ -644,7 +644,7 @@ static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL); #define FLASH_CMD_SET_NVMD 0x02
Quoted 4 lines
structflash_command{
- u8 command[8];
+ u8 command[8]__nonstring;
This looks a bit suboptimal ... is there anywhere in the kernel u8[] is actually used for real strings? In which case it would seem the better place to put the annotation is in the typedef for u8 arrays.
Regards,
James
Quoted 18 lines · James Bottomley
Quoted 17 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__nonstringto and correctly identify the char array as "not a C string" and thereby eliminate the warning.Cc Jack Wang <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc "Martin K. Petersen" <[email protected]>Signed-off-by Kees Cook <[email protected]>---
drivers/scsi/pm8001/pm8001_ctl.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 8 lines
drivers/scsi/pm8001/pm8001_ctl.c +0
-0@@ -644,7 +644,7 @@ static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL); #define FLASH_CMD_SET_NVMD 0x02Quoted 4 lines
structflash_command{
- u8 command[8];
+ u8 command[8]__nonstring;This looks a bit suboptimal ... is there anywhere in the kernel u8[] is actually used for real strings? In which case it would seem the better place to put the annotation is in the typedef for u8 arrays.
I answered this in a merged thread[1]. Can this get picked up?
Thanks!
-Kees
[1] https://lore.kernel.org/lkml/202503111520.CF7527A@keescook/
Signature · 1 line
Kees Cook
Martin K. Petersen
AppliedKees,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
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
__nonstringto and correctly identify the char array as "not a C string" and thereby eliminate the warning.
Applied to 6.16/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen