Skip to contentSkip to conversation

tw89: core.h: Replace zero-length array with flexible-array member

PATCH In review Gustavo A. R. Silva 5 participants 6 messages Feb 16, 2022 – Feb 21, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tw89: core.h: 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

---
 drivers/net/wireless/realtek/rtw89/core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/core.h +1 -1
index 7c84556ec4ad..b15b529e19ed 100644
@@ -2847,7 +2847,7 @@ struct rtw89_dev {
 	int napi_budget_countdown;
 
 	/* HCI related data, keep last */
-	u8 priv[0] __aligned(sizeof(void *));
+	u8 priv[] __aligned(sizeof(void *));
 };
 
 static inline int rtw89_hci_tx_write(struct rtw89_dev *rtwdev,
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

Signature · 1 line
Kees Cook
maintainer Acked-by
#2 lore raw
Quoted 17 lines

-----Original Message-----
From: Kees Cook <[email protected]>
Sent: Thursday, February 17, 2022 4:36 AM
To: Gustavo A. R. Silva <[email protected]>
Cc: Pkshih <[email protected]>; Kalle Valo <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH][next] tw89: core.h: Replace zero-length array with flexible-array member

Quoted 6 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].

Quoted 7 lines
Quoted 5 lines

[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

--
Ping-Ke

maintainer
#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 11 lines · On Wed, 16 Feb 2022 13:50:47 -0600 Gustavo A. R. Silva wrote:

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

The subject is off.

#4 lore raw
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 16 Feb 2022 13:50:47 -0600 Gustavo A. R. Silva wrote:

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].

Quoted 8 lines
Quoted 6 lines

[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

The subject is off.

I can fix that during commit.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#5 lore raw

Re: [next] rtw89: core.h: Replace zero-length array with flexible-array member

In reply to Gustavo A. R. Silva
Quoted 6 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].

Quoted 7 lines

[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

Patch applied to wireless-next.git, thanks.

2e2f63a19b0a rtw89: core.h: Replace zero-length array with flexible-array member

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/20220216195047.GA904198@embeddedor/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches