hpfs: Replace one-element array with flexible-array member
PATCH 1/1 hpfs: Replace one-element array with flexible-array member
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warning:
CC [M] fs/hpfs/dir.ofs/hpfs/dir.c: In function ‘hpfs_readdir’:fs/hpfs/dir.c:163:41: warning: array subscript 1 is above array bounds of ‘u8[1]’ {aka ‘unsigned char[1]’} [-Warray-bounds]
163 | || de ->name[0] != 1 || de->name[1] != 1))
| ~~~~~~~~^~~
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays
--- fs/hpfs/hpfs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/hpfs/hpfs.h +2 -1
@@ -356,7 +356,8 @@ struct hpfs_dirent {u8 no_of_acls;/* number of ACL's (low 3 bits) */ u8 ix;/* code page index (of filename), see struct code_page_data */ -u8 namelen, name[1 ];/* file name */ +u8 namelen;/* file name length */ +u8 name[];/* file name */ /* dnode_secno down; btree down pointer, if present, follows name on next word boundary, or maybe it precedes next dirent, which is on a word boundary. */
Signature · 1 line
2.27.0
Hi all,
Friendly ping: who can take this, please?
Thanks
--
Gustavo
Quoted 39 lines · Gustavo A. R. Silva
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warning:
CC [M]
fs/hpfs/dir.ofs/hpfs/dir.c: In function ‘hpfs_readdir’:fs/hpfs/dir.c:163:41: warning: array subscript 1 is above array bounds of ‘u8[1]’ {aka ‘unsigned char[1]’} [-Warray-bounds]
163 | || de ->name[0] != 1 || de->name[1] != 1))| ~~~~~~~~^~~[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arraysSigned-off-by Gustavo A. R. Silva <[email protected]>--- fs/hpfs/hpfs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/hpfs/hpfs.h +2
-1@@ -356,7 +356,8 @@ struct hpfs_dirent {u8 no_of_acls;/* number of ACL's (low 3 bits) */ u8 ix;/* code page index (of filename), see struct code_page_data */ -u8 namelen, name[1 ];/* file name */ +u8 namelen;/* file name length */ +u8 name[];/* file name */ /* dnode_secno down; btree down pointer, if present, follows name on next word boundary, or maybe it precedes next dirent, which is on a word boundary. */