Skip to contentSkip to conversation

ARM: ixp4xx: Replace 0-length arrays with flexible arrays

PATCH In review Kees Cook 2 participants 4 messages Jan 5, 2023 – Jan 16, 2023 Arm/Intel IXP4XX Arm architecture

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 ARM: ixp4xx: Replace 0-length arrays with flexible arrays

Zero-length arrays are deprecated[1]. Replace npe_load_firmware's union of 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:

drivers/soc/ixp4xx/ixp4xx-npe.c: In function 'npe_load_firmware':
drivers/soc/ixp4xx/ixp4xx-npe.c:570:60: warning: array subscript i is outside array bounds of 'u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
570 | image->data[i] = swab32(image->data[i]);
include/uapi/linux/swab.h:115:54: note: in definition of macro '__swab32'
115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
| ^
drivers/soc/ixp4xx/ixp4xx-npe.c:570:42: note: in expansion of macro 'swab32'
570 | image->data[i] = swab32(image->data[i]);
| ^~~~~~
drivers/soc/ixp4xx/ixp4xx-npe.c:522:29: note: while referencing 'data'
522 | u32 data[0];
| ^~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc Krzysztof Halasa <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
 drivers/soc/ixp4xx/ixp4xx-npe.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/soc/ixp4xx/ixp4xx-npe.c +3 -3
index 58240e320c13..5be9988f30ce 100644
@@ -519,15 +519,15 @@ int npe_load_firmware(struct npe *npe, const char *name, struct device *dev)
 		u32 id;
 		u32 size;
 		union {
-			u32 data[0];
-			struct dl_block blocks[0];
+			DECLARE_FLEX_ARRAY(u32, data);
+			DECLARE_FLEX_ARRAY(struct dl_block, blocks);
 		};
 	} *image;
 
 	struct dl_codeblock {
 		u32 npe_addr;
 		u32 size;
-		u32 data[0];
+		u32 data[];
 	} *cb;
 
 	int i, j, err, data_size, instr_size, blocks, table_end;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Kees Cook

Zero-length arrays are deprecated[1]. Replace npe_load_firmware's union of 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:

drivers/soc/ixp4xx/ixp4xx-npe.c: In function 'npe_load_firmware':
drivers/soc/ixp4xx/ixp4xx-npe.c:570:60: warning: array subscript i is outside array bounds of 'u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
570 | image->data[i] = swab32(image->data[i]);
include/uapi/linux/swab.h:115:54: note: in definition of macro '__swab32'
115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
| ^
drivers/soc/ixp4xx/ixp4xx-npe.c:570:42: note: in expansion of macro 'swab32'
570 | image->data[i] = swab32(image->data[i]);
| ^~~~~~
drivers/soc/ixp4xx/ixp4xx-npe.c:522:29: note: while referencing 'data'
522 | u32 data[0];
| ^~~~

Quoted 8 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc Krzysztof Halasa <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>

Looks good to me:

Do you need me to funnel this to the SoC tree or do you have some quickpath for fixes like this?

Yours,
Linus Walleij

author
#2 lore raw
Quoted 28 lines · Linus Walleij
Quoted 17 lines · Kees Cook

Zero-length arrays are deprecated[1]. Replace npe_load_firmware's union of 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:

drivers/soc/ixp4xx/ixp4xx-npe.c: In function 'npe_load_firmware':
drivers/soc/ixp4xx/ixp4xx-npe.c:570:60: warning: array subscript i is outside array bounds of 'u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
570 | image->data[i] = swab32(image->data[i]);
include/uapi/linux/swab.h:115:54: note: in definition of macro '__swab32'
115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
| ^
drivers/soc/ixp4xx/ixp4xx-npe.c:570:42: note: in expansion of macro 'swab32'
570 | image->data[i] = swab32(image->data[i]);
| ^~~~~~
drivers/soc/ixp4xx/ixp4xx-npe.c:522:29: note: while referencing 'data'
522 | u32 data[0];
| ^~~~

Quoted 8 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc Krzysztof Halasa <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
Quoted 2 lines

Looks good to me:

Thanks!

Quoted 2 lines

Do you need me to funnel this to the SoC tree or do you have some quickpath for fixes like this?

I'll take it via my tree if unless you'd rather it go through yours. Most maintainers take these directly, but some don't want to. I'm flexible! :)

Signature · 1 line
Kees Cook
#3 lore raw
Quoted 32 lines · Kees Cook
Quoted 28 lines · Linus Walleij
Quoted 17 lines · Kees Cook

Zero-length arrays are deprecated[1]. Replace npe_load_firmware's union of 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:

drivers/soc/ixp4xx/ixp4xx-npe.c: In function 'npe_load_firmware':
drivers/soc/ixp4xx/ixp4xx-npe.c:570:60: warning: array subscript i is outside array bounds of 'u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
570 | image->data[i] = swab32(image->data[i]);
include/uapi/linux/swab.h:115:54: note: in definition of macro '__swab32'
115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
| ^
drivers/soc/ixp4xx/ixp4xx-npe.c:570:42: note: in expansion of macro 'swab32'
570 | image->data[i] = swab32(image->data[i]);
| ^~~~~~
drivers/soc/ixp4xx/ixp4xx-npe.c:522:29: note: while referencing 'data'
522 | u32 data[0];
| ^~~~

Quoted 8 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc Krzysztof Halasa <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
Quoted 2 lines

Looks good to me:

Quoted 8 lines

Thanks!

Quoted 2 lines

Do you need me to funnel this to the SoC tree or do you have some quickpath for fixes like this?

I'll take it via my tree if unless you'd rather it go through yours. Most maintainers take these directly, but some don't want to. I'm flexible! :)

Just pick it into your tree, the IXP4xx is low activity and I do not submit new material every merge window, so this is easiest.

Thanks!
Linus Walleij