Skip to contentSkip to conversation

net/macmace: Replace zero-length array with DECLARE_FLEX_ARRAY() helper

PATCH Applied Atul Raut 5 participants 5 messages Jul 30, 2023 – Aug 1, 2023

Subsystems (2)
lore
Share & tools
lore

Atul Raut

author
#0 lore raw

PATCH 1/1 net/macmace: Replace zero-length array with DECLARE_FLEX_ARRAY() helper

Since zero-length arrays are deprecated, we are replacing them with C99 flexible-array members. As a result, instead of declaring a zero-length array, use the new DECLARE_FLEX_ARRAY() helper macro.

This fixes warnings such as:
./drivers/net/ethernet/apple/macmace.c:80:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

---
 drivers/net/ethernet/apple/macmace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/apple/macmace.c +1 -1
index 8fcaf1639920..8775c3234e91 100644
@@ -77,7 +77,7 @@ struct mace_frame {
 	u8	pad4;
 	u32	pad5;
 	u32	pad6;
-	u8	data[1];
+	DECLARE_FLEX_ARRAY(u8, data);
 	/* And frame continues.. */
 };
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 18 lines · Atul Raut

Since zero-length arrays are deprecated, we are replacing them with C99 flexible-array members. As a result, instead of declaring a zero-length array, use the new DECLARE_FLEX_ARRAY() helper macro.

This fixes warnings such as:
./drivers/net/ethernet/apple/macmace.c:80:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

---
 drivers/net/ethernet/apple/macmace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/apple/macmace.c +0 -0
index 8fcaf1639920..8775c3234e91 100644

drivers/net/ethernet/apple/macmace.c struct mace_frame { · line 80

Quoted 5 lines
drivers/net/ethernet/apple/macmace.c +1 -1
@@ -77,7 +77,7 @@ struct mace_frame {
 	u8	pad4;
 	u32	pad5;
 	u32	pad6;
-	u8	data[1];
+	DECLARE_FLEX_ARRAY(u8, data);

But data[1] is not zero-length array.

Quoted 7 lines
drivers/net/ethernet/apple/macmace.c +0 -0
 	/* And frame continues.. */
 };
 
Signature · 1 line
2.34.1
#2 lore raw
Quoted 14 lines · Leon Romanovsky
Quoted 13 lines · Atul Raut

Since zero-length arrays are deprecated, we are replacing them with C99 flexible-array members. As a result, instead of declaring a zero-length array, use the new DECLARE_FLEX_ARRAY() helper macro.

This fixes warnings such as:
./drivers/net/ethernet/apple/macmace.c:80:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

---
 drivers/net/ethernet/apple/macmace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/net/ethernet/apple/macmace.c struct mace_frame { · line 80

Quoted 10 lines
drivers/net/ethernet/apple/macmace.c +1 -1
index 8fcaf1639920..8775c3234e91 100644
@@ -77,7 +77,7 @@ struct mace_frame {
 	u8	pad4;
 	u32	pad5;
 	u32	pad6;
-	u8	data[1];
+	DECLARE_FLEX_ARRAY(u8, data);

But data[1] is not zero-length array.

So, please, if you are certain that data should be a flexible array, send v2 without calling data a zero-length array. Also, with such change, I think driver code could be improved in many places in the same patchset.

Quoted 8 lines
Quoted 7 lines
drivers/net/ethernet/apple/macmace.c +0 -0
 	/* And frame continues.. */
 };
 
Signature · 1 line
2.34.1
maintainer
#3 lore raw
Quoted 8 lines · On Tue, 1 Aug 2023 16:09:37 +0200 Larysa Zaremba wrote:
Quoted 4 lines

drivers/net/ethernet/apple/macmace.c struct mace_frame { · line 80

Quoted 2 lines
drivers/net/ethernet/apple/macmace.c +1 -1
-	u8	data[1];
+	DECLARE_FLEX_ARRAY(u8, data);  

But data[1] is not zero-length array.

So, please, if you are certain that data should be a flexible array, send v2 without calling data a zero-length array. Also, with such change, I think driver code could be improved in many places in the same patchset.

Atul, you should respond to reviewers promptly. These are legit questions.
On closer inspection the patch looks fine so to avoid clogging up the review queue and wasting more time on it I'm just going to apply it.

#4 lore raw
In reply to Atul Raut
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Sun, 30 Jul 2023 16:14:42 -0700 you wrote:

Since zero-length arrays are deprecated, we are replacing them with C99 flexible-array members. As a result, instead of declaring a zero-length array, use the new DECLARE_FLEX_ARRAY() helper macro.

This fixes warnings such as:
./drivers/net/ethernet/apple/macmace.c:80:4-8: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)

[...]

Here is the summary with links:
- net/macmace: Replace zero-length array with DECLARE_FLEX_ARRAY() helper

    https://git.kernel.org/netdev/net-next/c/005c9600003e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html