Skip to contentSkip to conversation

uapi: wireless: Replace zero-length array with flexible-array member

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Feb 16, 2022 – Mar 26, 2022 802.11 (including cfg80211/NL80211)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uapi: wireless: Replace zero-length 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].

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

---
 include/uapi/linux/wireless.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/wireless.h +1 -1
index 08967b3f19c8..3c2ad5fae17f 100644
@@ -835,7 +835,7 @@ struct iw_encode_ext {
 			       * individual keys */
 	__u16		alg; /* IW_ENCODE_ALG_* */
 	__u16		key_len;
-	__u8		key[0];
+	__u8		key[];
 };
 
 /* SIOCSIWMLME data */
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 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].

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

This UAPI change should be fine for any compiler that understood the older "[0]" syntax.

Signature · 1 line
Kees Cook
#2 lore raw
Quoted 10 lines · Kees Cook
Quoted 9 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].

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

Quoted 7 lines
Quoted 2 lines

This UAPI change should be fine for any compiler that understood the older "[0]" syntax.

Hi all,

Friendly ping: can someone take this, please?

...I can take this in my -next tree in the meantime.

Thanks
--
Gustavo