Skip to contentSkip to conversation

replace zero length arrays

PATCH Superseded Stephen Hemminger 12 participants 84 messages Jan 13, 2023 – Jan 23, 2024

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

cover replace zero length arrays

Zero length arrays are a GNU extension that has been superseded by flex arrays.

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

These are places found by cocci/zero_length_array.cocci

Stephen Hemminger (7):
member: replace zero length array with flex array
cryptodev: replace zero length array with flex array
security: replace zero length array with flex array
mlx5: replace zero length array with flex array
nfp: replace zero length array with flex array
enic: replace zero length array with flex array
dpaax: replace zero length array with flex array

 drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +-
 drivers/net/enic/base/vnic_devcmd.h        | 2 +-
 drivers/net/mlx5/mlx5.h                    | 4 ++--
 drivers/net/mlx5/mlx5_flow.h               | 2 +-
 drivers/net/mlx5/mlx5_tx.h                 | 2 +-
 drivers/net/nfp/flower/nfp_flower_cmsg.h   | 2 +-
 lib/cryptodev/cryptodev_pmd.h              | 2 +-
 lib/member/rte_member_heap.h               | 2 +-
 lib/security/rte_security_driver.h         | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.39.0
#1 lore raw

PATCH 1/7 member: replace zero length array with flex array

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/member/rte_member_heap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member_heap.h +1 -1
index 9c4a01aebe95..ab6319bc2de4 100644
@@ -26,7 +26,7 @@ struct hash {
 	uint16_t bkt_cnt;
 	uint16_t num_item;
 	uint32_t seed;
-	struct hash_bkt buckets[0];
+	struct hash_bkt buckets[];
 };
 
 struct node {
Signature · 1 line
2.39.0
#2 lore raw

Re: [PATCH 1/7] member: replace zero length array with flex array

Quoted 14 lines · Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/member/rte_member_heap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member_heap.h +0 -0
index 9c4a01aebe95..ab6319bc2de4 100644

lib/member/rte_member_heap.h struct hash { · line 32

Quoted 8 lines
lib/member/rte_member_heap.h +1 -1
@@ -26,7 +26,7 @@ struct hash {
 	uint16_t bkt_cnt;
 	uint16_t num_item;
 	uint32_t seed;
-	struct hash_bkt buckets[0];
+	struct hash_bkt buckets[];
 };
 
 struct node {

i suppose arguably this series depends on the series Bruce is putting up defaulting the minimum C standard to C99 since technically that's the minimum needed for the flexible array members.

#3 lore raw

Re: [PATCH 1/7] member: replace zero length array with flex array

Quoted 21 lines · On Fri, 13 Jan 2023 16:19:21 -0800 Tyler Retzlaff…
Quoted 20 lines · Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/member/rte_member_heap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member_heap.h +1 -1
index 9c4a01aebe95..ab6319bc2de4 100644
@@ -26,7 +26,7 @@ struct hash {
 	uint16_t bkt_cnt;
 	uint16_t num_item;
 	uint32_t seed;
-	struct hash_bkt buckets[0];
+	struct hash_bkt buckets[];
 };
 
Quoted 9 lines

lib/member/rte_member_heap.h struct hash { · line 32

Quoted 2 lines
lib/member/rte_member_heap.h +0 -0
 struct node {

i suppose arguably this series depends on the series Bruce is putting up defaulting the minimum C standard to C99 since technically that's the minimum needed for the flexible array members.

There is already flex array usage in several places in DPDK. Therefore this won't be raising the requirements.

#4 lore raw

Re: [PATCH 1/7] member: replace zero length array with flex array

Quoted 31 lines · Stephen Hemminger
Quoted 28 lines · On Fri, 13 Jan 2023 16:19:21 -0800 Tyler Retzlaff…
Quoted 14 lines · Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/member/rte_member_heap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member_heap.h +0 -0
index 9c4a01aebe95..ab6319bc2de4 100644

lib/member/rte_member_heap.h struct hash { · line 32

Quoted 8 lines
lib/member/rte_member_heap.h +1 -1
@@ -26,7 +26,7 @@ struct hash {
 	uint16_t bkt_cnt;
 	uint16_t num_item;
 	uint32_t seed;
-	struct hash_bkt buckets[0];
+	struct hash_bkt buckets[];
 };
 
 struct node {

i suppose arguably this series depends on the series Bruce is putting up defaulting the minimum C standard to C99 since technically that's the minimum needed for the flexible array members.

Quoted 5 lines
Quoted 2 lines

There is already flex array usage in several places in DPDK. Therefore this won't be raising the requirements.

agreed.

#5 lore raw

PATCH 2/7 cryptodev: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/cryptodev/cryptodev_pmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/cryptodev_pmd.h +1 -1
index 0020102eb7db..ffca31db4a96 100644
@@ -153,7 +153,7 @@ struct rte_cryptodev_sym_session {
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 	/**< Second cache line - start of the driver session data */
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Driver specific session data, variable size */
 };
 
Signature · 1 line
2.39.0
#6 lore raw

PATCH 3/7 security: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/security/rte_security_driver.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/security/rte_security_driver.h +1 -1
index 421e6f778067..ff6a33369a08 100644
@@ -34,7 +34,7 @@ struct rte_security_session {
 	/**< session private data IOVA address */
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Private session material, variable size (depends on driver) */
 };
 
Signature · 1 line
2.39.0
#7 lore raw

PATCH 4/7 mlx5: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/mlx5/mlx5.h      | 4 ++--
 drivers/net/mlx5/mlx5_flow.h | 2 +-
 drivers/net/mlx5/mlx5_tx.h   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.h +2 -2
index 31982002ee9b..2b295f9ba037 100644
@@ -1273,7 +1273,7 @@ struct mlx5_aso_ct_pool {
 	};
 	struct mlx5_aso_sq *sq; /* Async ASO SQ. */
 	struct mlx5_aso_sq *shared_sq; /* Shared ASO SQ. */
-	struct mlx5_aso_ct_action actions[0];
+	struct mlx5_aso_ct_action actions[];
 	/* CT action structures bulk. */
 };
 
@@ -1290,7 +1290,7 @@ struct mlx5_aso_ct_pools_mng {
 	rte_spinlock_t ct_sl; /* The ASO CT free list lock. */
 	rte_rwlock_t resize_rwl; /* The ASO CT pool resize lock. */
 	struct aso_ct_list free_cts; /* Free ASO CT objects list. */
-	struct mlx5_aso_sq aso_sqs[0]; /* ASO queue objects. */
+	struct mlx5_aso_sq aso_sqs[]; /* ASO queue objects. */
 };
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_flow.h +1 -1
index 1f57ecd6e1c1..e12efab211d2 100644
@@ -1149,7 +1149,7 @@ struct rte_flow_hw {
 	uint32_t age_idx;
 	cnt_id_t cnt_id;
 	uint32_t mtr_id;
-	uint8_t rule[0]; /* HWS layer data struct. */
+	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_tx.h +1 -1
index a44050a1cec3..d026e8126a75 100644
@@ -166,7 +166,7 @@ struct mlx5_txq_data {
 	struct mlx5_txq_stats stats; /* TX queue counters. */
 	struct mlx5_txq_stats stats_reset; /* stats on last reset. */
 	struct mlx5_uar_data uar_data;
-	struct rte_mbuf *elts[0];
+	struct rte_mbuf * elts[];
 	/* Storage for queued packets, must be the last field. */
 } __rte_cache_aligned;
 
Signature · 1 line
2.39.0
#8 lore raw

Re: [PATCH 4/7] mlx5: replace zero length array with flex array

Quoted 5 lines · On Fri, 13 Jan 2023 13:52:02 -0800 Stephen Hemminger…

Zero length arrays are GNU extension. Replace with standard flex array.

---

Since Mlx driver enables pedantic checking, this causes build failure on some versions of gcc.

In file included from ../drivers/net/mlx5/mlx5.c:40:
../drivers/net/mlx5/mlx5_tx.h:187:23: error: invalid use of structure with flexible array member [-Werror=pedantic] 187 | struct mlx5_txq_data txq; /* Data path structure. */
| ^~~

Understand that the driver wants to enable more checking since Nvidia does good job of keeping the code up to date. But having driver specific compiler flags like this creates more unnecessary complexity and doesn't improve the resulting code.

#9 lore raw

RE: [PATCH 4/7] mlx5: replace zero length array with flex array

Hi, Stephen

IIUC - for now all of the compilers claimed for DPDK compilation support the zero-length-array and we do not have an issue ? We could eliminate this GNU extension and have workaround, like this:

/* Verbs headers do not support -pedantic. */
#ifdef PEDANTIC
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include <infiniband/mlx5dv.h>
#include <infiniband/verbs.h>
#ifdef PEDANTIC
#pragma GCC diagnostic error "-Wpedantic"
#endif

I'm not sure this would make code more readable.
Should we do this WA?

With best regards,
Slava

Quoted 32 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: суббота, 14 января 2023 г. 19:08
To: [email protected]
Cc: Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: Re: [PATCH 4/7] mlx5: replace zero length array with flex array

Quoted 5 lines · On Fri, 13 Jan 2023 13:52:02 -0800 Stephen Hemminger…

Zero length arrays are GNU extension. Replace with standard flex array.

---

Since Mlx driver enables pedantic checking, this causes build failure on some versions of gcc.

In file included from ../drivers/net/mlx5/mlx5.c:40:
../drivers/net/mlx5/mlx5_tx.h:187:23: error: invalid use of structure with flexible array member [-Werror=pedantic]
187 | struct mlx5_txq_data txq; /* Data path structure. */
| ^~~

Understand that the driver wants to enable more checking since Nvidia does good job of keeping the code up to date. But having driver specific compiler flags like this creates more unnecessary complexity and doesn't improve the resulting code.

#10 lore raw

PATCH 5/7 nfp: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_cmsg.h +1 -1
index 04601cb0bd25..ee8b439d617f 100644
@@ -73,7 +73,7 @@ struct nfp_flower_cmsg_mac_repr {
 		uint8_t info;
 		uint8_t nbi_port;
 		uint8_t phys_port;
-	} ports[0];
+	} ports[];
 };
 
 /*
Signature · 1 line
2.39.0
Acked-by on v1 5/7
#11 lore raw

Re: [PATCH 5/7] nfp: replace zero length array with flex array

Hi Stephen,

Thanks for your patch.

Quoted 4 lines · Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

I understand this works might depend on another work to raise the minimum compiler versions to support this change. Provided this is sorted out as part of the full series to move to flex arrays, for the change itself.

Quoted 20 lines
---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_cmsg.h +1 -1
index 04601cb0bd25..ee8b439d617f 100644
@@ -73,7 +73,7 @@ struct nfp_flower_cmsg_mac_repr {
 		uint8_t info;
 		uint8_t nbi_port;
 		uint8_t phys_port;
-	} ports[0];
+	} ports[];
 };
 
 /*
Signature · 1 line
2.39.0
Signature · 2 lines
Kind Regards,
Niklas Söderlund
#12 lore raw

PATCH 6/7 enic: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/enic/base/vnic_devcmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/base/vnic_devcmd.h +1 -1
index 253a791c3f65..f91cc3078d63 100644
@@ -765,7 +765,7 @@ struct vnic_devcmd_notify {
 struct vnic_devcmd_provinfo {
 	uint8_t oui[3];
 	uint8_t type;
-	uint8_t data[0];
+	uint8_t data[];
 };
 
 /*
Signature · 1 line
2.39.0
Acked-by on v1 6/7
#13 lore raw

Re: [PATCH 6/7] enic: replace zero length array with flex array

From: Stephen Hemminger <[email protected]>
Date: Friday, January 13, 2023 at 1:52 PM
To: [email protected] <[email protected]>
Cc: Stephen Hemminger <[email protected]>, John Daley (johndale) <[email protected]>, Hyong Youb Kim (hyonkim) <[email protected]>
Subject: [PATCH 6/7] enic: replace zero length array with flex array
Zero length arrays are GNU extension. Replace with
standard flex array.

---
 drivers/net/enic/base/vnic_devcmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/base/vnic_devcmd.h +1 -1
index 253a791c3f65..f91cc3078d63 100644
@@ -765,7 +765,7 @@ struct vnic_devcmd_notify {
 struct vnic_devcmd_provinfo {
         uint8_t oui[3];
         uint8_t type;
-       uint8_t data[0];
+       uint8_t data[];
 };
 
 /*

--
2.39.0

#14 lore raw

PATCH 7/7 dpaax: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/dpaax/caamflib/desc/ipsec.h +1 -1
index 8ec6aac915b4..2c9080a1b51d 100644
@@ -350,7 +350,7 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];
+	uint8_t ip_hdr[];
 };
 
 static inline unsigned int
Signature · 1 line
2.39.0
#17 lore raw

v2 cover replace zero length arrays

In reply to Stephen Hemminger

Zero length arrays are a GNU extension that has been superseded by flex arrays.

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

These are places found by cocci/zero_length_array.cocci

v2 - rebased on 23.11-rc3
more places started using zero length array

Stephen Hemminger (10):
member: replace zero length array with flex array
cryptodev: replace zero length array with flex array
security: replace zero length array with flex array
pipeline: replace zero length array with flex array net/nfp: replace zero length array with flex array net/enic: replace zero length array with flex array net/mlx5: replace zero length array with flex array
pdcp: replace zero length array with flex array net/cpfl: replace zero length array with flex array common/dpaxx: replace zero length array with flex array

 drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +-
 drivers/common/mlx5/mlx5_prm.h             | 2 +-
 drivers/net/cpfl/cpfl_flow_engine_fxp.c    | 2 +-
 drivers/net/enic/base/vnic_devcmd.h        | 2 +-
 drivers/net/mlx5/mlx5.h                    | 4 ++--
 drivers/net/mlx5/mlx5_flow.h               | 2 +-
 drivers/net/mlx5/mlx5_tx.h                 | 2 +-
 drivers/net/nfp/flower/nfp_flower_cmsg.h   | 2 +-
 lib/cryptodev/cryptodev_pmd.h              | 2 +-
 lib/member/rte_member_heap.h               | 2 +-
 lib/pdcp/pdcp_entity.h                     | 2 +-
 lib/pipeline/rte_swx_pipeline_internal.h   | 2 +-
 lib/security/rte_security_driver.h         | 2 +-
 13 files changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.42.0
#18 lore raw

PATCH v2 1/10 member: replace zero length array with flex array

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/member/rte_member_heap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member_heap.h +1 -1
index 9c4a01aebe95..ab6319bc2de4 100644
@@ -26,7 +26,7 @@ struct hash {
 	uint16_t bkt_cnt;
 	uint16_t num_item;
 	uint32_t seed;
-	struct hash_bkt buckets[0];
+	struct hash_bkt buckets[];
 };
 
 struct node {
Signature · 1 line
2.42.0
#20 lore raw

PATCH v2 2/10 cryptodev: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/cryptodev/cryptodev_pmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/cryptodev_pmd.h +1 -1
index 3bb3d95c1338..0732b356883c 100644
@@ -153,7 +153,7 @@ struct rte_cryptodev_sym_session {
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 	/**< Second cache line - start of the driver session data */
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Driver specific session data, variable size */
 };
 
Signature · 1 line
2.42.0
#22 lore raw

PATCH v2 3/10 security: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/security/rte_security_driver.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/security/rte_security_driver.h +1 -1
index 62664dacdbb4..faa4074f1965 100644
@@ -33,7 +33,7 @@ struct rte_security_session {
 	/**< session private data IOVA address */
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Private session material, variable size (depends on driver) */
 };
 
Signature · 1 line
2.42.0
#24 lore raw

PATCH v2 4/10 pipeline: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/pipeline/rte_swx_pipeline_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pipeline/rte_swx_pipeline_internal.h +1 -1
index a67b6e965de7..8ec12263b989 100644
@@ -213,7 +213,7 @@ TAILQ_HEAD(rss_tailq, rss);
 
 struct rss_runtime {
 	uint32_t key_size; /* key size in bytes. */
-	uint8_t key[0]; /* key. */
+	uint8_t key[]; /* key. */
 };
 
 /*
Signature · 1 line
2.42.0
#26 lore raw

PATCH v2 5/10 net/nfp: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_cmsg.h +1 -1
index c2938fb6f63c..f00d2e838d8f 100644
@@ -73,7 +73,7 @@ struct nfp_flower_cmsg_mac_repr {
 		uint8_t info;
 		uint8_t nbi_port;
 		uint8_t phys_port;
-	} ports[0];
+	} ports[];
 };
 
 /*
Signature · 1 line
2.42.0
#28 lore raw

PATCH v2 6/10 net/enic: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/enic/base/vnic_devcmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/base/vnic_devcmd.h +1 -1
index 253a791c3f65..f91cc3078d63 100644
@@ -765,7 +765,7 @@ struct vnic_devcmd_notify {
 struct vnic_devcmd_provinfo {
 	uint8_t oui[3];
 	uint8_t type;
-	uint8_t data[0];
+	uint8_t data[];
 };
 
 /*
Signature · 1 line
2.42.0
#30 lore raw

PATCH v2 7/10 net/mlx5: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/common/mlx5/mlx5_prm.h | 2 +-
 drivers/net/mlx5/mlx5.h        | 4 ++--
 drivers/net/mlx5/mlx5_flow.h   | 2 +-
 drivers/net/mlx5/mlx5_tx.h     | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/common/mlx5/mlx5_prm.h +1 -1
index 9e22dce6da13..932b89bd79d3 100644
@@ -5181,7 +5181,7 @@ struct mlx5_ifc_flow_context_bits {
 	u8 reserved_at_e0[0x40];
 	u8 encrypt_decrypt_obj_id[0x20];
 	u8 reserved_at_140[0x16c0];
-	union mlx5_ifc_dest_format_flow_counter_list_auto_bits destination[0];
+	union mlx5_ifc_dest_format_flow_counter_list_auto_bits destination[];
 };
 
 struct mlx5_ifc_set_fte_in_bits {
drivers/net/mlx5/mlx5.h +2 -2
index f0d63a0ba5f5..89d13900fd3c 100644
@@ -1308,7 +1308,7 @@ struct mlx5_aso_ct_pool {
 	};
 	struct mlx5_aso_sq *sq; /* Async ASO SQ. */
 	struct mlx5_aso_sq *shared_sq; /* Shared ASO SQ. */
-	struct mlx5_aso_ct_action actions[0];
+	struct mlx5_aso_ct_action actions[];
 	/* CT action structures bulk. */
 };
 
@@ -1325,7 +1325,7 @@ struct mlx5_aso_ct_pools_mng {
 	rte_spinlock_t ct_sl; /* The ASO CT free list lock. */
 	rte_rwlock_t resize_rwl; /* The ASO CT pool resize lock. */
 	struct aso_ct_list free_cts; /* Free ASO CT objects list. */
-	struct mlx5_aso_sq aso_sqs[0]; /* ASO queue objects. */
+	struct mlx5_aso_sq aso_sqs[]; /* ASO queue objects. */
 };
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_flow.h +1 -1
index 6dde9de688b9..b35079b30a6e 100644
@@ -1257,7 +1257,7 @@ struct rte_flow_hw {
 	cnt_id_t cnt_id;
 	uint32_t mtr_id;
 	uint32_t rule_idx;
-	uint8_t rule[0]; /* HWS layer data struct. */
+	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_tx.h +1 -1
index e59ce37667ba..2045e5174e6d 100644
@@ -171,7 +171,7 @@ struct mlx5_txq_data {
 	struct mlx5_txq_stats stats; /* TX queue counters. */
 	struct mlx5_txq_stats stats_reset; /* stats on last reset. */
 	struct mlx5_uar_data uar_data;
-	struct rte_mbuf *elts[0];
+	struct rte_mbuf *elts[];
 	/* Storage for queued packets, must be the last field. */
 } __rte_cache_aligned;
 
Signature · 1 line
2.42.0
#32 lore raw

PATCH v2 8/10 pdcp: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/pdcp/pdcp_entity.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pdcp/pdcp_entity.h +1 -1
index 4fc6342a5ced..f854192e98dc 100644
@@ -185,7 +185,7 @@ struct entity_priv_dl_part {
 	/** Reorder packet buffer */
 	struct pdcp_reorder reorder;
 	/** Bitmap memory region */
-	uint8_t bitmap_mem[0];
+	uint8_t bitmap_mem[];
 };
 
 struct entity_priv_ul_part {
Signature · 1 line
2.42.0
#35 lore raw

PATCH v2 9/10 net/cpfl: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/cpfl/cpfl_flow_engine_fxp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/cpfl/cpfl_flow_engine_fxp.c +1 -1
index 8a4e1419b4db..39a281fa61ee 100644
@@ -53,7 +53,7 @@ struct cpfl_rule_info_meta {
 	uint32_t pr_num;			/* number of pattern rules */
 	uint32_t mr_num;			/* number of modification rules */
 	uint32_t rule_num;			/* number of all rules */
-	struct cpfl_rule_info rules[0];
+	struct cpfl_rule_info rules[];
 };
 
 static uint32_t cpfl_fxp_mod_idx_alloc(struct cpfl_adapter_ext *ad);
Signature · 1 line
2.42.0
#37 lore raw

PATCH v2 10/10 common/dpaxx: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/dpaax/caamflib/desc/ipsec.h +1 -1
index 95fc3ea5ba3b..7bd82e4d0639 100644
@@ -350,7 +350,7 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];
+	uint8_t ip_hdr[];
 };
 
 static inline unsigned int
Signature · 1 line
2.42.0
#40 lore raw
Quoted 3 lines · On Fri, 17 Nov 2023 09:31:11 +0100 Morten Brørup <[email protected]>…

Suggest checkpatches to disallow this, if it doesn't already.

Unfortunately, matching this with awk is too hard. Coccinelle can do it but don't want to introduce dependency on that.

Maybe a compiler flag would be possible, but could not find one.

#41 lore raw
Quoted 11 lines · Stephen Hemminger
Quoted 3 lines · On Fri, 17 Nov 2023 09:31:11 +0100 Morten Brørup <[email protected]>…

Suggest checkpatches to disallow this, if it doesn't already.

Unfortunately, matching this with awk is too hard. Coccinelle can do it but don't want to introduce dependency on that.

Maybe a compiler flag would be possible, but could not find one.

-pedantic will warn, but to use it without clobbering the build with warnings we would probably need to qualify all use of non-standard extensions with the __extension__ keyword.

```
struct foo {
        int a;
        int b;
        char buffer[0];
};
```
zhora ~> gcc -Wall -pedantic oink.c
oink.c:7:14: warning: ISO C forbids zero-size array ‘buffer’ [-Wpedantic]
    7 |         char buffer[0];
#42 lore raw

v4 cover Replace zero length arrays

In reply to Stephen Hemminger

Zero length arrays are a GNU extension that has been superseded by flex arrays.

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

These are places found by cocci/zero_length_array.cocci

v4 - fix issues reported by clang where zero length
array was embedded in security structures in cn10k and txq being embedded in mlx5 was missing extension

Stephen Hemminger (10):
member: replace zero length array with flex array
cryptodev: replace zero length array with flex array
security: replace zero length array with flex array
pipeline: replace zero length array with flex array net/nfp: replace zero length array with flex array net/enic: replace zero length array with flex array net/mlx5: replace zero length array with flex array
pdcp: replace zero length array with flex array net/cpfl: replace zero length array with flex array common/dpaxx: remove zero length array

 drivers/common/dpaax/caamflib/desc/ipsec.h | 6 ++----
 drivers/common/mlx5/mlx5_prm.h             | 2 +-
 drivers/crypto/cnxk/cn10k_ipsec.h          | 4 +++-
 drivers/crypto/cnxk/cn9k_ipsec.h           | 4 +++-
 drivers/crypto/cnxk/cnxk_se.h              | 5 ++++-
 drivers/net/cpfl/cpfl_flow_engine_fxp.c    | 2 +-
 drivers/net/enic/base/vnic_devcmd.h        | 2 +-
 drivers/net/mlx5/mlx5.h                    | 4 ++--
 drivers/net/mlx5/mlx5_flow.h               | 2 +-
 drivers/net/mlx5/mlx5_tx.h                 | 3 ++-
 drivers/net/nfp/flower/nfp_flower_cmsg.h   | 2 +-
 lib/cryptodev/cryptodev_pmd.h              | 2 +-
 lib/member/rte_member_heap.h               | 2 +-
 lib/pdcp/pdcp_entity.h                     | 2 +-
 lib/pipeline/rte_swx_pipeline_internal.h   | 2 +-
 lib/security/rte_security_driver.h         | 2 +-
 16 files changed, 26 insertions(+), 20 deletions(-)
Signature · 1 line
2.42.0
#43 lore raw

PATCH v4 1/10 member: replace zero length array with flex array

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/member/rte_member_heap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member_heap.h +1 -1
index 9c4a01aebe95..ab6319bc2de4 100644
@@ -26,7 +26,7 @@ struct hash {
 	uint16_t bkt_cnt;
 	uint16_t num_item;
 	uint32_t seed;
-	struct hash_bkt buckets[0];
+	struct hash_bkt buckets[];
 };
 
 struct node {
Signature · 1 line
2.42.0
#44 lore raw

PATCH v4 2/10 cryptodev: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/crypto/cnxk/cnxk_se.h | 5 ++++-
 lib/cryptodev/cryptodev_pmd.h | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/crypto/cnxk/cnxk_se.h +4 -1
index c2a807fa9428..f86b859a08a4 100644
@@ -29,8 +29,11 @@ enum cpt_dp_thread_type {
 	CPT_DP_THREAD_TYPE_PT,
 };
 
+#define SYM_SESS_SIZE sizeof(struct rte_cryptodev_sym_session)
+
 struct cnxk_se_sess {
-	struct rte_cryptodev_sym_session rte_sess;
+	uint8_t rte_sess[SYM_SESS_SIZE];
+
 	uint8_t aes_gcm : 1;
 	uint8_t aes_ccm : 1;
 	uint8_t aes_ctr : 1;
lib/cryptodev/cryptodev_pmd.h +1 -1
index 3bb3d95c1338..0732b356883c 100644
@@ -153,7 +153,7 @@ struct rte_cryptodev_sym_session {
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 	/**< Second cache line - start of the driver session data */
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Driver specific session data, variable size */
 };
 
Signature · 1 line
2.42.0
#46 lore raw

PATCH v4 3/10 security: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/crypto/cnxk/cn10k_ipsec.h  | 4 +++-
 drivers/crypto/cnxk/cn9k_ipsec.h   | 4 +++-
 lib/security/rte_security_driver.h | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)
drivers/crypto/cnxk/cn10k_ipsec.h +3 -1
index 8a93d7406204..144bc8319dea 100644
@@ -24,8 +24,10 @@ struct cn10k_ipsec_sa {
 	};
 } __rte_aligned(ROC_ALIGN);
 
+#define SEC_SESS_SIZE sizeof(struct rte_security_session)
+
 struct cn10k_sec_session {
-	struct rte_security_session rte_sess;
+	uint8_t rte_sess[SEC_SESS_SIZE];
 
 	/** PMD private space */
 
drivers/crypto/cnxk/cn9k_ipsec.h +3 -1
index 1ea946afd8a9..d28642e3a627 100644
@@ -20,8 +20,10 @@ struct cn9k_ipsec_sa {
 	};
 } __rte_aligned(8);
 
+#define SEC_SESS_SIZE sizeof(struct rte_security_session)
+
 struct cn9k_sec_session {
-	struct rte_security_session rte_sess;
+	uint8_t rte_sess[SEC_SESS_SIZE];
 
 	/** PMD private space */
 
lib/security/rte_security_driver.h +1 -1
index 62664dacdbb4..faa4074f1965 100644
@@ -33,7 +33,7 @@ struct rte_security_session {
 	/**< session private data IOVA address */
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Private session material, variable size (depends on driver) */
 };
 
Signature · 1 line
2.42.0
#48 lore raw

PATCH v4 4/10 pipeline: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/pipeline/rte_swx_pipeline_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pipeline/rte_swx_pipeline_internal.h +1 -1
index a67b6e965de7..8ec12263b989 100644
@@ -213,7 +213,7 @@ TAILQ_HEAD(rss_tailq, rss);
 
 struct rss_runtime {
 	uint32_t key_size; /* key size in bytes. */
-	uint8_t key[0]; /* key. */
+	uint8_t key[]; /* key. */
 };
 
 /*
Signature · 1 line
2.42.0
#49 lore raw

PATCH v4 5/10 net/nfp: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_cmsg.h +1 -1
index c2938fb6f63c..f00d2e838d8f 100644
@@ -73,7 +73,7 @@ struct nfp_flower_cmsg_mac_repr {
 		uint8_t info;
 		uint8_t nbi_port;
 		uint8_t phys_port;
-	} ports[0];
+	} ports[];
 };
 
 /*
Signature · 1 line
2.42.0
Acked-by on v4 5/10
#50 lore raw

RE: [PATCH v4 05/10] net/nfp: replace zero length array with flex array

Quoted 25 lines

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_cmsg.h +1 -2
index c2938fb6f63c..f00d2e838d8f 100644
@@ -73,7 +73,7 @@ struct nfp_flower_cmsg_mac_repr {
 		uint8_t info;
 		uint8_t nbi_port;
 		uint8_t phys_port;
-	} ports[0];
+	} ports[];
 };
 
 /*
--

2.42.0

#51 lore raw

PATCH v4 6/10 net/enic: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/enic/base/vnic_devcmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/base/vnic_devcmd.h +1 -1
index 253a791c3f65..f91cc3078d63 100644
@@ -765,7 +765,7 @@ struct vnic_devcmd_notify {
 struct vnic_devcmd_provinfo {
 	uint8_t oui[3];
 	uint8_t type;
-	uint8_t data[0];
+	uint8_t data[];
 };
 
 /*
Signature · 1 line
2.42.0
#52 lore raw

PATCH v4 7/10 net/mlx5: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/common/mlx5/mlx5_prm.h | 2 +-
 drivers/net/mlx5/mlx5.h        | 4 ++--
 drivers/net/mlx5/mlx5_flow.h   | 2 +-
 drivers/net/mlx5/mlx5_tx.h     | 3 ++-
 4 files changed, 6 insertions(+), 5 deletions(-)
drivers/common/mlx5/mlx5_prm.h +1 -1
index 9e22dce6da13..932b89bd79d3 100644
@@ -5181,7 +5181,7 @@ struct mlx5_ifc_flow_context_bits {
 	u8 reserved_at_e0[0x40];
 	u8 encrypt_decrypt_obj_id[0x20];
 	u8 reserved_at_140[0x16c0];
-	union mlx5_ifc_dest_format_flow_counter_list_auto_bits destination[0];
+	union mlx5_ifc_dest_format_flow_counter_list_auto_bits destination[];
 };
 
 struct mlx5_ifc_set_fte_in_bits {
drivers/net/mlx5/mlx5.h +2 -2
index f0d63a0ba5f5..89d13900fd3c 100644
@@ -1308,7 +1308,7 @@ struct mlx5_aso_ct_pool {
 	};
 	struct mlx5_aso_sq *sq; /* Async ASO SQ. */
 	struct mlx5_aso_sq *shared_sq; /* Shared ASO SQ. */
-	struct mlx5_aso_ct_action actions[0];
+	struct mlx5_aso_ct_action actions[];
 	/* CT action structures bulk. */
 };
 
@@ -1325,7 +1325,7 @@ struct mlx5_aso_ct_pools_mng {
 	rte_spinlock_t ct_sl; /* The ASO CT free list lock. */
 	rte_rwlock_t resize_rwl; /* The ASO CT pool resize lock. */
 	struct aso_ct_list free_cts; /* Free ASO CT objects list. */
-	struct mlx5_aso_sq aso_sqs[0]; /* ASO queue objects. */
+	struct mlx5_aso_sq aso_sqs[]; /* ASO queue objects. */
 };
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_flow.h +1 -1
index 6dde9de688b9..b35079b30a6e 100644
@@ -1257,7 +1257,7 @@ struct rte_flow_hw {
 	cnt_id_t cnt_id;
 	uint32_t mtr_id;
 	uint32_t rule_idx;
-	uint8_t rule[0]; /* HWS layer data struct. */
+	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_tx.h +2 -1
index e59ce37667ba..b1e8ea19a2a1 100644
@@ -171,11 +171,12 @@ struct mlx5_txq_data {
 	struct mlx5_txq_stats stats; /* TX queue counters. */
 	struct mlx5_txq_stats stats_reset; /* stats on last reset. */
 	struct mlx5_uar_data uar_data;
-	struct rte_mbuf *elts[0];
+	struct rte_mbuf *elts[];
 	/* Storage for queued packets, must be the last field. */
 } __rte_cache_aligned;
 
 /* TX queue control descriptor. */
+__extension__
 struct mlx5_txq_ctrl {
 	LIST_ENTRY(mlx5_txq_ctrl) next; /* Pointer to the next element. */
 	uint32_t refcnt; /* Reference counter. */
Signature · 1 line
2.42.0
Acked-by on v4 7/10
#53 lore raw

RE: [PATCH v4 07/10] net/mlx5: replace zero length array with flex array

Hi,

Quoted 7 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, November 20, 2023 18:07
Subject: [PATCH v4 07/10] net/mlx5: replace zero length array with flex array

Zero length arrays are GNU extension. Replace with standard flex array.

Quoted 8 lines
---
 drivers/common/mlx5/mlx5_prm.h | 2 +-
 drivers/net/mlx5/mlx5.h        | 4 ++--
 drivers/net/mlx5/mlx5_flow.h   | 2 +-
 drivers/net/mlx5/mlx5_tx.h     | 3 ++-
 4 files changed, 6 insertions(+), 5 deletions(-)

Look good to me. Thank you.

Best regards,
Dariusz Sosnowski

#54 lore raw

PATCH v4 8/10 pdcp: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/pdcp/pdcp_entity.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pdcp/pdcp_entity.h +1 -1
index 4fc6342a5ced..f854192e98dc 100644
@@ -185,7 +185,7 @@ struct entity_priv_dl_part {
 	/** Reorder packet buffer */
 	struct pdcp_reorder reorder;
 	/** Bitmap memory region */
-	uint8_t bitmap_mem[0];
+	uint8_t bitmap_mem[];
 };
 
 struct entity_priv_ul_part {
Signature · 1 line
2.42.0
#55 lore raw

PATCH v4 9/10 net/cpfl: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/cpfl/cpfl_flow_engine_fxp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/cpfl/cpfl_flow_engine_fxp.c +1 -1
index 8a4e1419b4db..39a281fa61ee 100644
@@ -53,7 +53,7 @@ struct cpfl_rule_info_meta {
 	uint32_t pr_num;			/* number of pattern rules */
 	uint32_t mr_num;			/* number of modification rules */
 	uint32_t rule_num;			/* number of all rules */
-	struct cpfl_rule_info rules[0];
+	struct cpfl_rule_info rules[];
 };
 
 static uint32_t cpfl_fxp_mod_idx_alloc(struct cpfl_adapter_ext *ad);
Signature · 1 line
2.42.0
#56 lore raw

PATCH v4 10/10 common/dpaxx: remove zero length array

In reply to Stephen Hemminger

There is a place holder zero length array in this driver. But since the structure is embedded in other structures, it could not have been safely used anyway.
There doesn't appear to be any uses of it in the current code.

---
 drivers/common/dpaax/caamflib/desc/ipsec.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/common/dpaax/caamflib/desc/ipsec.h +2 -4
index 95fc3ea5ba3b..9d59b93292f9 100644
@@ -336,7 +336,6 @@ struct ipsec_encap_gcm {
  * @ip_hdr_len: optional IP Header length (in bytes)
  *  reserved - 16b
  *  Opt. IP Hdr Len - 16b
- * @ip_hdr: optional IP Header content (only for IPsec legacy mode)
  */
 struct ipsec_encap_pdb {
 	uint32_t options;
@@ -350,7 +349,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];
 };
 
 static inline unsigned int
@@ -776,7 +774,7 @@ cnstr_shdsc_ipsec_encap(uint32_t *descbuf, bool ps, bool swap,
 		PROGRAM_SET_36BIT_ADDR(p);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
 	SET_LABEL(p, hdr);
 	pkeyjmp = JUMP(p, keyjmp, LOCAL_JUMP, ALL_TRUE, BOTH|SHRD);
 	if (authdata->keylen)
@@ -913,7 +911,7 @@ cnstr_shdsc_ipsec_encap_des_aes_xcbc(uint32_t *descbuf,
 	PROGRAM_CNTXT_INIT(p, descbuf, 0);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
 	SET_LABEL(p, hdr);
 	pkeyjump = JUMP(p, keyjump, LOCAL_JUMP, ALL_TRUE, SHRD | SELF);
 	/*
Signature · 1 line
2.42.0
#57 lore raw

RE: [PATCH v4 10/10] common/dpaxx: remove zero length array

Quoted 24 lines

There is a place holder zero length array in this driver. But since the structure is embedded in other structures, it could not have been safely used anyway.
There doesn't appear to be any uses of it in the current code.

---
 drivers/common/dpaax/caamflib/desc/ipsec.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/common/dpaax/caamflib/desc/ipsec.h +0 -1
index 95fc3ea5ba3b..9d59b93292f9 100644
@@ -336,7 +336,6 @@ struct ipsec_encap_gcm {
  * @ip_hdr_len: optional IP Header length (in bytes)
  *  reserved - 16b
  *  Opt. IP Hdr Len - 16b
- * @ip_hdr: optional IP Header content (only for IPsec legacy mode)
  */
 struct ipsec_encap_pdb {
 	uint32_t options;

drivers/common/dpaax/caamflib/desc/ipsec.h struct ipsec_encap_pdb { · line 353

Quoted 4 lines
drivers/common/dpaax/caamflib/desc/ipsec.h +0 -1
@@ -350,7 +349,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];

[Hemant] This should be replaced with

	uint8_t ip_hdr[];

drivers/common/dpaax/caamflib/desc/ipsec.h cnstr_shdsc_ipsec_encap(uint32_t *descbuf, bool ps, · line 778

Quoted 10 lines
drivers/common/dpaax/caamflib/desc/ipsec.h +1 -1
 };
 
 static inline unsigned int
@@ -776,7 +774,7 @@ cnstr_shdsc_ipsec_encap(uint32_t *descbuf, bool ps,
 bool swap,
 		PROGRAM_SET_36BIT_ADDR(p);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+

[Hemant] Don't remove it. It will break the code.

drivers/common/dpaax/caamflib/desc/ipsec.h cnstr_shdsc_ipsec_encap_des_aes_xcbc(uint32_t · line 915

Quoted 10 lines
drivers/common/dpaax/caamflib/desc/ipsec.h +0 -0
 	SET_LABEL(p, hdr);
 	pkeyjmp = JUMP(p, keyjmp, LOCAL_JUMP, ALL_TRUE, BOTH|SHRD);
drivers/common/dpaax/caamflib/desc/ipsec.h +1 -1
 	if (authdata->keylen)
@@ -913,7 +911,7 @@ cnstr_shdsc_ipsec_encap_des_aes_xcbc(uint32_t
 *descbuf,
 	PROGRAM_CNTXT_INIT(p, descbuf, 0);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+

[Hemant] Don't remove it

Quoted 6 lines
drivers/common/dpaax/caamflib/desc/ipsec.h +0 -0
 	SET_LABEL(p, hdr);
 	pkeyjump = JUMP(p, keyjump, LOCAL_JUMP, ALL_TRUE, SHRD |

SELF);
/*
--
2.42.0

#58 lore raw

Re: [PATCH v4 10/10] common/dpaxx: remove zero length array

Quoted 11 lines · On Tue, 21 Nov 2023 10:49:59 +0000 Hemant Agrawal <[email protected]>…

drivers/common/dpaax/caamflib/desc/ipsec.h struct ipsec_encap_pdb { · line 353

Quoted 7 lines

struct ipsec_encap_pdb {

drivers/common/dpaax/caamflib/desc/ipsec.h +0 -1
 	uint32_t options;
@@ -350,7 +349,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];  

[Hemant] This should be replaced with

	uint8_t ip_hdr[];
Quoted 2 lines
(quoted diff) +0 -0
 };
 

That won't work because the structure is embedded in another struct and then clang will correctly report an error.

#59 lore raw

Re: [PATCH v4 10/10] common/dpaxx: remove zero length array

Quoted 12 lines · On Tue, 21 Nov 2023 08:46:41 -0800 Stephen Hemminger…
Quoted 9 lines · On Tue, 21 Nov 2023 10:49:59 +0000 Hemant Agrawal <[email protected]>…

drivers/common/dpaax/caamflib/desc/ipsec.h struct ipsec_encap_pdb { · line 353

Quoted 7 lines

struct ipsec_encap_pdb {

drivers/common/dpaax/caamflib/desc/ipsec.h +0 -1
 	uint32_t options;
@@ -350,7 +349,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];    

[Hemant] This should be replaced with

	uint8_t ip_hdr[];  
Quoted 5 lines
Quoted 2 lines

Review struct ipsec_encap_pdb { · line 353

Quoted 2 lines
(quoted diff) +0 -0
 };
 

That won't work because the structure is embedded in another struct and then clang will correctly report an error.

[2155/2868] Compiling C object drivers..._jr.a.p/crypto_caam_jr_caam_jr_uio.c.o
In file included from ../drivers/crypto/caam_jr/caam_jr_uio.c:23:
../drivers/crypto/caam_jr/caam_jr_pvt.h:139:25: warning: field 'encap_pdb' with variable sized type 'struct ipsec_encap_pdb' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]

        struct ipsec_encap_pdb encap_pdb;
                               ^

1 warning generated.
[2160/2868] Compiling C object drivers...m_jr.a.p/crypto_caam_jr_caam_jr_hw.c.o
In file included from ../drivers/crypto/caam_jr/caam_jr_hw.c:16:
../drivers/crypto/caam_jr/caam_jr_pvt.h:139:25: warning: field 'encap_pdb' with variable sized type 'struct ipsec_encap_pdb' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]

        struct ipsec_encap_pdb encap_pdb;
                               ^

1 warning generated.
[2174/2868] Compiling C object drivers....p/crypto_dpaa_sec_dpaa_sec_raw_dp.c.o
In file included from ../drivers/crypto/dpaa_sec/dpaa_sec_raw_dp.c:17:
../drivers/crypto/dpaa_sec/dpaa_sec.h:190:27: warning: field 'encap_pdb' with variable sized type 'struct ipsec_encap_pdb' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]

                        struct ipsec_encap_pdb encap_pdb;
                                               ^

1 warning generated.
[2176/2868] Compiling C object drivers...caam_jr.a.p/crypto_caam_jr_caam_jr.c.o
In file included from ../drivers/crypto/caam_jr/caam_jr.c:23:
../drivers/crypto/caam_jr/caam_jr_pvt.h:139:25: warning: field 'encap_pdb' with variable sized type 'struct ipsec_encap_pdb' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]

        struct ipsec_encap_pdb encap_pdb;
                               ^

1 warning generated.
[2246/2868] Compiling C object drivers...a_sec.a.p/crypto_dpaa_sec_dpaa_sec.c.o
In file included from ../drivers/crypto/dpaa_sec/dpaa_sec.c:43:
../drivers/crypto/dpaa_sec/dpaa_sec.h:190:27: warning: field 'encap_pdb' with variable sized type 'struct ipsec_encap_pdb' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]

                        struct ipsec_encap_pdb encap_pdb;
                                               ^

1 warning generated.

#60 lore raw

Re: [PATCH v4 10/10] common/dpaxx: remove zero length array

In reply to Stephen Hemminger
Quoted 12 lines · Stephen Hemminger
Quoted 9 lines · On Tue, 21 Nov 2023 10:49:59 +0000 Hemant Agrawal <[email protected]>…

drivers/common/dpaax/caamflib/desc/ipsec.h struct ipsec_encap_pdb { · line 353

Quoted 7 lines

struct ipsec_encap_pdb {

drivers/common/dpaax/caamflib/desc/ipsec.h +0 -1
 	uint32_t options;
@@ -350,7 +349,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];  

[Hemant] This should be replaced with

	uint8_t ip_hdr[];
Quoted 5 lines
Quoted 2 lines

Review struct ipsec_encap_pdb { · line 353

Quoted 2 lines
(quoted diff) +0 -0
 };
 

That won't work because the structure is embedded in another struct and then clang will correctly report an error.

Hemant if the field is not referenced what's the harm in removing it?

#61 lore raw

RE: [PATCH v4 10/10] common/dpaxx: remove zero length array

Quoted 24 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Tuesday, November 21, 2023 10:49 PM
To: Stephen Hemminger <[email protected]>
Cc: Hemant Agrawal <[email protected]>; [email protected]; Sachin Saxena <[email protected]>; Gagandeep Singh <[email protected]>
Subject: Re: [PATCH v4 10/10] common/dpaxx: remove zero length array
Importance: High

Quoted 12 lines · Stephen Hemminger
Quoted 9 lines · On Tue, 21 Nov 2023 10:49:59 +0000 Hemant Agrawal <[email protected]>…

drivers/common/dpaax/caamflib/desc/ipsec.h struct ipsec_encap_pdb { · line 353

Quoted 7 lines

struct ipsec_encap_pdb {

drivers/common/dpaax/caamflib/desc/ipsec.h +0 -1
 	uint32_t options;
@@ -350,7 +349,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];

[Hemant] This should be replaced with

	uint8_t ip_hdr[];
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Review struct ipsec_encap_pdb { · line 353

Quoted 2 lines
(quoted diff) +0 -0
 };
 

That won't work because the structure is embedded in another struct and then clang will correctly report an error.

Hemant if the field is not referenced what's the harm in removing it?

It is being used indirectly, e.g. dpaa_sec.h usages it for ip address description preparation for the hardware.

            struct ipsec_encap_pdb encap_pdb;
            union {
                struct ip ip4_hdr;
                struct rte_ipv6_hdr ip6_hdr;
            };

We need to change it, however in the interim, I will like to add "-Wno-gnu-variable-sized-type-not-at-end" for both caam_jr and dpaa_sec to avoid this warning.

#62 lore raw

Re: [PATCH v4 10/10] common/dpaxx: remove zero length array

Quoted 32 lines · On Wed, 22 Nov 2023 07:23:36 +0000 Hemant Agrawal <[email protected]>…
Quoted 22 lines

-----Original Message-----
From: Tyler Retzlaff <[email protected]>
Sent: Tuesday, November 21, 2023 10:49 PM
To: Stephen Hemminger <[email protected]>
Cc: Hemant Agrawal <[email protected]>; [email protected]; Sachin Saxena <[email protected]>; Gagandeep Singh <[email protected]>
Subject: Re: [PATCH v4 10/10] common/dpaxx: remove zero length array
Importance: High

Quoted 12 lines · Stephen Hemminger
Quoted 9 lines · On Tue, 21 Nov 2023 10:49:59 +0000 Hemant Agrawal <[email protected]>…

drivers/common/dpaax/caamflib/desc/ipsec.h struct ipsec_encap_pdb { · line 353

Quoted 7 lines

struct ipsec_encap_pdb {

drivers/common/dpaax/caamflib/desc/ipsec.h +0 -1
 	uint32_t options;
@@ -350,7 +349,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];  

[Hemant] This should be replaced with

	uint8_t ip_hdr[];  
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Review struct ipsec_encap_pdb { · line 353

Quoted 2 lines
(quoted diff) +0 -0
 };
 

That won't work because the structure is embedded in another struct and then clang will correctly report an error.

Hemant if the field is not referenced what's the harm in removing it?

It is being used indirectly, e.g. dpaa_sec.h usages it for ip address description preparation for the hardware.

Quoted 7 lines
            struct ipsec_encap_pdb encap_pdb;
            union {
                struct ip ip4_hdr;
                struct rte_ipv6_hdr ip6_hdr;
            };

We need to change it, however in the interim, I will like to add "-Wno-gnu-variable-sized-type-not-at-end" for both caam_jr and dpaa_sec to avoid this warning.

Ok, there are several ways to fix that. Driver specific compiler flags are the one that is least favored.

#63 lore raw

Re: [PATCH v4 10/10] common/dpaxx: remove zero length array

In reply to Hemant Agrawal

This is a better alternative.

From 52c805b9526dbef62377276c4499c997fbc96268 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <[email protected]>
Date: Thu, 23 Nov 2023 11:12:02 -0800
Subject: [PATCH] common/dpaxx: replace zero length array

The zero length ip_header is used as an overlay to the encap IP header. Since the code is already assuming the layout of the structure, replace the array with direct access.

---
 drivers/common/dpaax/caamflib/desc/ipsec.h | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/common/dpaax/caamflib/desc/ipsec.h +14 -6
index 95fc3ea5ba3b..d1411cc6aab4 100644
@@ -334,9 +334,7 @@ struct ipsec_encap_gcm {
  * @seq_num: IPsec sequence number
  * @spi: IPsec SPI (Security Parameters Index)
  * @ip_hdr_len: optional IP Header length (in bytes)
- *  reserved - 16b
- *  Opt. IP Hdr Len - 16b
- * @ip_hdr: optional IP Header content (only for IPsec legacy mode)
+ *  Ip header must follow directly after ipsec_encap_pdb
  */
 struct ipsec_encap_pdb {
 	uint32_t options;
@@ -350,7 +348,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];
 };
 
 static inline unsigned int
@@ -776,7 +773,12 @@ cnstr_shdsc_ipsec_encap(uint32_t *descbuf, bool ps, bool swap,
 		PROGRAM_SET_36BIT_ADDR(p);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
+	/* ip header if any follows the encap_pdb */
+	if (pdb->ip_hdr_len > 0) {
+		void *ip_hdr = pdb + 1;
+		COPY_DATA(p, ip_hdr, pdb->ip_hdr_len);
+	}
 	SET_LABEL(p, hdr);
 	pkeyjmp = JUMP(p, keyjmp, LOCAL_JUMP, ALL_TRUE, BOTH|SHRD);
 	if (authdata->keylen)
@@ -913,7 +915,13 @@ cnstr_shdsc_ipsec_encap_des_aes_xcbc(uint32_t *descbuf,
 	PROGRAM_CNTXT_INIT(p, descbuf, 0);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
+	/* ip header if any follows the encap_pdb */
+	if (pdb->ip_hdr_len > 0) {
+		void *ip_hdr = pdb + 1;
+		COPY_DATA(p, ip_hdr, pdb->ip_hdr_len);
+	}
+
 	SET_LABEL(p, hdr);
 	pkeyjump = JUMP(p, keyjump, LOCAL_JUMP, ALL_TRUE, SHRD | SELF);
 	/*
Signature · 1 line
2.42.0
#64 lore raw

RE: [PATCH v4 10/10] common/dpaxx: remove zero length array

Quoted 84 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, November 24, 2023 12:49 AM
To: Hemant Agrawal <[email protected]>
Cc: Tyler Retzlaff <[email protected]>; [email protected]; Sachin Saxena <[email protected]>; Gagandeep Singh <[email protected]>
Subject: Re: [PATCH v4 10/10] common/dpaxx: remove zero length array
Importance: High

This is a better alternative.

From 52c805b9526dbef62377276c4499c997fbc96268 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <[email protected]>
Date: Thu, 23 Nov 2023 11:12:02 -0800
Subject: [PATCH] common/dpaxx: replace zero length array

The zero length ip_header is used as an overlay to the encap IP header. Since the code is already assuming the layout of the structure, replace the array with direct access.

---
 drivers/common/dpaax/caamflib/desc/ipsec.h | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/common/dpaax/caamflib/desc/ipsec.h +7 -5
index 95fc3ea5ba3b..d1411cc6aab4 100644
@@ -334,9 +334,7 @@ struct ipsec_encap_gcm {
  * @seq_num: IPsec sequence number
  * @spi: IPsec SPI (Security Parameters Index)
  * @ip_hdr_len: optional IP Header length (in bytes)
- *  reserved - 16b
- *  Opt. IP Hdr Len - 16b
- * @ip_hdr: optional IP Header content (only for IPsec legacy mode)
+ *  Ip header must follow directly after ipsec_encap_pdb
  */
 struct ipsec_encap_pdb {
 	uint32_t options;
@@ -350,7 +348,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];
 };
 
 static inline unsigned int
@@ -776,7 +773,12 @@ cnstr_shdsc_ipsec_encap(uint32_t *descbuf, bool
 ps, bool swap,
 		PROGRAM_SET_36BIT_ADDR(p);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
+	/* ip header if any follows the encap_pdb */
+	if (pdb->ip_hdr_len > 0) {
+		void *ip_hdr = pdb + 1;
+		COPY_DATA(p, ip_hdr, pdb->ip_hdr_len);
+	}
 	SET_LABEL(p, hdr);
 	pkeyjmp = JUMP(p, keyjmp, LOCAL_JUMP, ALL_TRUE, BOTH|SHRD);
drivers/common/dpaax/caamflib/desc/ipsec.h +7 -1
 	if (authdata->keylen)
@@ -913,7 +915,13 @@ cnstr_shdsc_ipsec_encap_des_aes_xcbc(uint32_t
 *descbuf,
 	PROGRAM_CNTXT_INIT(p, descbuf, 0);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
+	/* ip header if any follows the encap_pdb */
+	if (pdb->ip_hdr_len > 0) {
+		void *ip_hdr = pdb + 1;
+		COPY_DATA(p, ip_hdr, pdb->ip_hdr_len);
+	}
+
 	SET_LABEL(p, hdr);
 	pkeyjump = JUMP(p, keyjump, LOCAL_JUMP, ALL_TRUE, SHRD |

SELF);
/*
--
2.42.0

#65 lore raw

RE: [PATCH v4 00/10] Replace zero length arrays

In reply to Stephen Hemminger
Quoted 6 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 20 November 2023 18.07

Zero length arrays are a GNU extension that has been superseded by flex arrays.

Quoted 7 lines

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

These are places found by cocci/zero_length_array.cocci

v4 - fix issues reported by clang where zero length
array was embedded in security structures in cn10k and txq being embedded in mlx5 was missing extension

Thanks for cleaning this up.

#66 lore raw

Re: [PATCH v4 00/10] Replace zero length arrays

Quoted 18 lines · Morten Brørup
Quoted 6 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 20 November 2023 18.07

Zero length arrays are a GNU extension that has been superseded by flex arrays.

Quoted 7 lines

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

These are places found by cocci/zero_length_array.cocci

v4 - fix issues reported by clang where zero length
array was embedded in security structures in cn10k and txq being embedded in mlx5 was missing extension

Thanks for cleaning this up.

#67 lore raw

v5 cover Replace zero length arrays

In reply to Stephen Hemminger

Zero length arrays are a GNU extension that has been superseded by flex arrays.

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

These are places found by cocci/zero_length_array.cocci

v5 - revised version of dpaxx ip_hdr fix

     rebase to 23.11

Stephen Hemminger (10):
member: replace zero length array with flex array
cryptodev: replace zero length array with flex array
security: replace zero length array with flex array
pipeline: replace zero length array with flex array net/nfp: replace zero length array with flex array net/enic: replace zero length array with flex array net/mlx5: replace zero length array with flex array
pdcp: replace zero length array with flex array net/cpfl: replace zero length array with flex array common/dpaxx: replace zero length array

 drivers/common/dpaax/caamflib/desc/ipsec.h | 20 ++++++++++++++------
 drivers/common/mlx5/mlx5_prm.h             |  2 +-
 drivers/crypto/cnxk/cn10k_ipsec.h          |  4 +++-
 drivers/crypto/cnxk/cn9k_ipsec.h           |  4 +++-
 drivers/crypto/cnxk/cnxk_se.h              |  5 ++++-
 drivers/net/cpfl/cpfl_flow_engine_fxp.c    |  2 +-
 drivers/net/enic/base/vnic_devcmd.h        |  2 +-
 drivers/net/mlx5/mlx5.h                    |  4 ++--
 drivers/net/mlx5/mlx5_flow.h               |  2 +-
 drivers/net/mlx5/mlx5_tx.h                 |  3 ++-
 drivers/net/nfp/flower/nfp_flower_cmsg.h   |  2 +-
 lib/cryptodev/cryptodev_pmd.h              |  2 +-
 lib/member/rte_member_heap.h               |  2 +-
 lib/pdcp/pdcp_entity.h                     |  2 +-
 lib/pipeline/rte_swx_pipeline_internal.h   |  2 +-
 lib/security/rte_security_driver.h         |  2 +-
 16 files changed, 38 insertions(+), 22 deletions(-)
Signature · 1 line
2.42.0
#68 lore raw

PATCH v5 1/10 member: replace zero length array with flex array

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/member/rte_member_heap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member_heap.h +1 -1
index 9c4a01aebe95..ab6319bc2de4 100644
@@ -26,7 +26,7 @@ struct hash {
 	uint16_t bkt_cnt;
 	uint16_t num_item;
 	uint32_t seed;
-	struct hash_bkt buckets[0];
+	struct hash_bkt buckets[];
 };
 
 struct node {
Signature · 1 line
2.42.0
#69 lore raw

PATCH v5 2/10 cryptodev: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/crypto/cnxk/cnxk_se.h | 5 ++++-
 lib/cryptodev/cryptodev_pmd.h | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/crypto/cnxk/cnxk_se.h +4 -1
index c2a807fa9428..f86b859a08a4 100644
@@ -29,8 +29,11 @@ enum cpt_dp_thread_type {
 	CPT_DP_THREAD_TYPE_PT,
 };
 
+#define SYM_SESS_SIZE sizeof(struct rte_cryptodev_sym_session)
+
 struct cnxk_se_sess {
-	struct rte_cryptodev_sym_session rte_sess;
+	uint8_t rte_sess[SYM_SESS_SIZE];
+
 	uint8_t aes_gcm : 1;
 	uint8_t aes_ccm : 1;
 	uint8_t aes_ctr : 1;
lib/cryptodev/cryptodev_pmd.h +1 -1
index 3bb3d95c1338..0732b356883c 100644
@@ -153,7 +153,7 @@ struct rte_cryptodev_sym_session {
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 	/**< Second cache line - start of the driver session data */
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Driver specific session data, variable size */
 };
 
Signature · 1 line
2.42.0
#70 lore raw

PATCH v5 3/10 security: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/crypto/cnxk/cn10k_ipsec.h  | 4 +++-
 drivers/crypto/cnxk/cn9k_ipsec.h   | 4 +++-
 lib/security/rte_security_driver.h | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)
drivers/crypto/cnxk/cn10k_ipsec.h +3 -1
index 8a93d7406204..144bc8319dea 100644
@@ -24,8 +24,10 @@ struct cn10k_ipsec_sa {
 	};
 } __rte_aligned(ROC_ALIGN);
 
+#define SEC_SESS_SIZE sizeof(struct rte_security_session)
+
 struct cn10k_sec_session {
-	struct rte_security_session rte_sess;
+	uint8_t rte_sess[SEC_SESS_SIZE];
 
 	/** PMD private space */
 
drivers/crypto/cnxk/cn9k_ipsec.h +3 -1
index 1ea946afd8a9..d28642e3a627 100644
@@ -20,8 +20,10 @@ struct cn9k_ipsec_sa {
 	};
 } __rte_aligned(8);
 
+#define SEC_SESS_SIZE sizeof(struct rte_security_session)
+
 struct cn9k_sec_session {
-	struct rte_security_session rte_sess;
+	uint8_t rte_sess[SEC_SESS_SIZE];
 
 	/** PMD private space */
 
lib/security/rte_security_driver.h +1 -1
index 62664dacdbb4..faa4074f1965 100644
@@ -33,7 +33,7 @@ struct rte_security_session {
 	/**< session private data IOVA address */
 
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
-	uint8_t driver_priv_data[0];
+	uint8_t driver_priv_data[];
 	/**< Private session material, variable size (depends on driver) */
 };
 
Signature · 1 line
2.42.0
#71 lore raw

PATCH v5 4/10 pipeline: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/pipeline/rte_swx_pipeline_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pipeline/rte_swx_pipeline_internal.h +1 -1
index a67b6e965de7..8ec12263b989 100644
@@ -213,7 +213,7 @@ TAILQ_HEAD(rss_tailq, rss);
 
 struct rss_runtime {
 	uint32_t key_size; /* key size in bytes. */
-	uint8_t key[0]; /* key. */
+	uint8_t key[]; /* key. */
 };
 
 /*
Signature · 1 line
2.42.0
#72 lore raw

PATCH v5 5/10 net/nfp: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_cmsg.h +1 -1
index c2938fb6f63c..f00d2e838d8f 100644
@@ -73,7 +73,7 @@ struct nfp_flower_cmsg_mac_repr {
 		uint8_t info;
 		uint8_t nbi_port;
 		uint8_t phys_port;
-	} ports[0];
+	} ports[];
 };
 
 /*
Signature · 1 line
2.42.0
Acked-by on v5 5/10
#73 lore raw

RE: [PATCH v5 05/10] net/nfp: replace zero length array with flex array

Looks good to me, thanks.

Quoted 35 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, November 29, 2023 10:39 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Niklas Söderlund <[email protected]>; Tyler Retzlaff <[email protected]>; Chaoyong He <[email protected]>
Subject: [PATCH v5 05/10] net/nfp: replace zero length array with flex array

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_cmsg.h +1 -2
index c2938fb6f63c..f00d2e838d8f 100644
@@ -73,7 +73,7 @@ struct nfp_flower_cmsg_mac_repr {
 		uint8_t info;
 		uint8_t nbi_port;
 		uint8_t phys_port;
-	} ports[0];
+	} ports[];
 };
 
 /*
--

2.42.0

#74 lore raw

PATCH v5 6/10 net/enic: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/enic/base/vnic_devcmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/base/vnic_devcmd.h +1 -1
index 253a791c3f65..f91cc3078d63 100644
@@ -765,7 +765,7 @@ struct vnic_devcmd_notify {
 struct vnic_devcmd_provinfo {
 	uint8_t oui[3];
 	uint8_t type;
-	uint8_t data[0];
+	uint8_t data[];
 };
 
 /*
Signature · 1 line
2.42.0
#75 lore raw

PATCH v5 7/10 net/mlx5: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/common/mlx5/mlx5_prm.h | 2 +-
 drivers/net/mlx5/mlx5.h        | 4 ++--
 drivers/net/mlx5/mlx5_flow.h   | 2 +-
 drivers/net/mlx5/mlx5_tx.h     | 3 ++-
 4 files changed, 6 insertions(+), 5 deletions(-)
drivers/common/mlx5/mlx5_prm.h +1 -1
index 9e22dce6da13..932b89bd79d3 100644
@@ -5181,7 +5181,7 @@ struct mlx5_ifc_flow_context_bits {
 	u8 reserved_at_e0[0x40];
 	u8 encrypt_decrypt_obj_id[0x20];
 	u8 reserved_at_140[0x16c0];
-	union mlx5_ifc_dest_format_flow_counter_list_auto_bits destination[0];
+	union mlx5_ifc_dest_format_flow_counter_list_auto_bits destination[];
 };
 
 struct mlx5_ifc_set_fte_in_bits {
drivers/net/mlx5/mlx5.h +2 -2
index 263ebead7f29..f2e2e04429d1 100644
@@ -1314,7 +1314,7 @@ struct mlx5_aso_ct_pool {
 	};
 	struct mlx5_aso_sq *sq; /* Async ASO SQ. */
 	struct mlx5_aso_sq *shared_sq; /* Shared ASO SQ. */
-	struct mlx5_aso_ct_action actions[0];
+	struct mlx5_aso_ct_action actions[];
 	/* CT action structures bulk. */
 };
 
@@ -1331,7 +1331,7 @@ struct mlx5_aso_ct_pools_mng {
 	rte_spinlock_t ct_sl; /* The ASO CT free list lock. */
 	rte_rwlock_t resize_rwl; /* The ASO CT pool resize lock. */
 	struct aso_ct_list free_cts; /* Free ASO CT objects list. */
-	struct mlx5_aso_sq aso_sqs[0]; /* ASO queue objects. */
+	struct mlx5_aso_sq aso_sqs[]; /* ASO queue objects. */
 };
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_flow.h +1 -1
index 6dde9de688b9..b35079b30a6e 100644
@@ -1257,7 +1257,7 @@ struct rte_flow_hw {
 	cnt_id_t cnt_id;
 	uint32_t mtr_id;
 	uint32_t rule_idx;
-	uint8_t rule[0]; /* HWS layer data struct. */
+	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
 #ifdef PEDANTIC
drivers/net/mlx5/mlx5_tx.h +2 -1
index e59ce37667ba..b1e8ea19a2a1 100644
@@ -171,11 +171,12 @@ struct mlx5_txq_data {
 	struct mlx5_txq_stats stats; /* TX queue counters. */
 	struct mlx5_txq_stats stats_reset; /* stats on last reset. */
 	struct mlx5_uar_data uar_data;
-	struct rte_mbuf *elts[0];
+	struct rte_mbuf *elts[];
 	/* Storage for queued packets, must be the last field. */
 } __rte_cache_aligned;
 
 /* TX queue control descriptor. */
+__extension__
 struct mlx5_txq_ctrl {
 	LIST_ENTRY(mlx5_txq_ctrl) next; /* Pointer to the next element. */
 	uint32_t refcnt; /* Reference counter. */
Signature · 1 line
2.42.0
#76 lore raw

Re: [PATCH v5 07/10] net/mlx5: replace zero length array with flex array

29/11/2023 03:39, Stephen Hemminger:

Quoted 4 lines
drivers/net/mlx5/mlx5_tx.h +0 -0
@@ -171,11 +171,12 @@ struct mlx5_txq_data {
 	struct mlx5_txq_stats stats; /* TX queue counters. */

drivers/net/mlx5/mlx5_tx.h struct mlx5_txq_data { · line 180

Quoted 10 lines
drivers/net/mlx5/mlx5_tx.h +2 -1
 	struct mlx5_txq_stats stats_reset; /* stats on last reset. */
 	struct mlx5_uar_data uar_data;
-	struct rte_mbuf *elts[0];
+	struct rte_mbuf *elts[];
 	/* Storage for queued packets, must be the last field. */
 } __rte_cache_aligned;
 
 /* TX queue control descriptor. */
+__extension__
 struct mlx5_txq_ctrl {

struct mlx5_txq_data is included at the end of struct mlx5_txq_ctrl I don't understand why we need to declare an extension here.

#77 lore raw

Re: [PATCH v5 07/10] net/mlx5: replace zero length array with flex array

23/01/2024 10:44, Thomas Monjalon:

Quoted 12 lines

29/11/2023 03:39, Stephen Hemminger:

Quoted 11 lines
drivers/net/mlx5/mlx5_tx.h +1 -1
@@ -171,11 +171,12 @@ struct mlx5_txq_data {
 	struct mlx5_txq_stats stats; /* TX queue counters. */
 	struct mlx5_txq_stats stats_reset; /* stats on last reset. */
 	struct mlx5_uar_data uar_data;
-	struct rte_mbuf *elts[0];
+	struct rte_mbuf *elts[];
 	/* Storage for queued packets, must be the last field. */
 } __rte_cache_aligned;
 
Quoted 6 lines

drivers/net/mlx5/mlx5_tx.h struct mlx5_txq_data { · line 180

Quoted 3 lines
drivers/net/mlx5/mlx5_tx.h +1 -0
 /* TX queue control descriptor. */
+__extension__
 struct mlx5_txq_ctrl {

struct mlx5_txq_data is included at the end of struct mlx5_txq_ctrl I don't understand why we need to declare an extension here.

If I remove __extension__:
error: invalid use of structure with flexible array member [-Werror=pedantic]

Is it a problem only in pedantic mode?

#78 lore raw

RE: [PATCH v5 07/10] net/mlx5: replace zero length array with flex array

From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 23, 2024 11:28

Quoted 20 lines

23/01/2024 10:44, Thomas Monjalon:

Quoted 12 lines

29/11/2023 03:39, Stephen Hemminger:

Quoted 11 lines
drivers/net/mlx5/mlx5_tx.h +1 -1
@@ -171,11 +171,12 @@ struct mlx5_txq_data {
    struct mlx5_txq_stats stats; /* TX queue counters. */
    struct mlx5_txq_stats stats_reset; /* stats on last reset. */
    struct mlx5_uar_data uar_data;
-   struct rte_mbuf *elts[0];
+   struct rte_mbuf *elts[];
    /* Storage for queued packets, must be the last field. */  }
 __rte_cache_aligned;
 
Quoted 6 lines

drivers/net/mlx5/mlx5_tx.h struct mlx5_txq_data { · line 180

Quoted 3 lines
drivers/net/mlx5/mlx5_tx.h +1 -0
 /* TX queue control descriptor. */
+__extension__
 struct mlx5_txq_ctrl {

struct mlx5_txq_data is included at the end of struct mlx5_txq_ctrl I don't understand why we need to declare an extension here.

Quoted 4 lines

If I remove __extension__:
error: invalid use of structure with flexible array member [-Werror=pedantic]

Is it a problem only in pedantic mode?

Yes, because this usage is nonstandard. Using a struct which has a flexible array member, inside another struct is a compiler extension.

Best regards,
Dariusz Sosnowski

#79 lore raw

PATCH v5 8/10 pdcp: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 lib/pdcp/pdcp_entity.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pdcp/pdcp_entity.h +1 -1
index 4fc6342a5ced..f854192e98dc 100644
@@ -185,7 +185,7 @@ struct entity_priv_dl_part {
 	/** Reorder packet buffer */
 	struct pdcp_reorder reorder;
 	/** Bitmap memory region */
-	uint8_t bitmap_mem[0];
+	uint8_t bitmap_mem[];
 };
 
 struct entity_priv_ul_part {
Signature · 1 line
2.42.0
#80 lore raw

PATCH v5 9/10 net/cpfl: replace zero length array with flex array

In reply to Stephen Hemminger

Zero length arrays are GNU extension. Replace with standard flex array.

---
 drivers/net/cpfl/cpfl_flow_engine_fxp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/cpfl/cpfl_flow_engine_fxp.c +1 -1
index 8a4e1419b4db..39a281fa61ee 100644
@@ -53,7 +53,7 @@ struct cpfl_rule_info_meta {
 	uint32_t pr_num;			/* number of pattern rules */
 	uint32_t mr_num;			/* number of modification rules */
 	uint32_t rule_num;			/* number of all rules */
-	struct cpfl_rule_info rules[0];
+	struct cpfl_rule_info rules[];
 };
 
 static uint32_t cpfl_fxp_mod_idx_alloc(struct cpfl_adapter_ext *ad);
Signature · 1 line
2.42.0
#81 lore raw

PATCH v5 10/10 common/dpaxx: replace zero length array

In reply to Stephen Hemminger

The zero length ip_header is used as an overlay to the encap IP header. Since the code is already assuming the layout of the structure, replace the array with direct access.

---
 drivers/common/dpaax/caamflib/desc/ipsec.h | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/common/dpaax/caamflib/desc/ipsec.h +14 -6
index 95fc3ea5ba3b..d1411cc6aab4 100644
@@ -334,9 +334,7 @@ struct ipsec_encap_gcm {
  * @seq_num: IPsec sequence number
  * @spi: IPsec SPI (Security Parameters Index)
  * @ip_hdr_len: optional IP Header length (in bytes)
- *  reserved - 16b
- *  Opt. IP Hdr Len - 16b
- * @ip_hdr: optional IP Header content (only for IPsec legacy mode)
+ *  Ip header must follow directly after ipsec_encap_pdb
  */
 struct ipsec_encap_pdb {
 	uint32_t options;
@@ -350,7 +348,6 @@ struct ipsec_encap_pdb {
 	};
 	uint32_t spi;
 	uint32_t ip_hdr_len;
-	uint8_t ip_hdr[0];
 };
 
 static inline unsigned int
@@ -776,7 +773,12 @@ cnstr_shdsc_ipsec_encap(uint32_t *descbuf, bool ps, bool swap,
 		PROGRAM_SET_36BIT_ADDR(p);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
+	/* ip header if any follows the encap_pdb */
+	if (pdb->ip_hdr_len > 0) {
+		void *ip_hdr = pdb + 1;
+		COPY_DATA(p, ip_hdr, pdb->ip_hdr_len);
+	}
 	SET_LABEL(p, hdr);
 	pkeyjmp = JUMP(p, keyjmp, LOCAL_JUMP, ALL_TRUE, BOTH|SHRD);
 	if (authdata->keylen)
@@ -913,7 +915,13 @@ cnstr_shdsc_ipsec_encap_des_aes_xcbc(uint32_t *descbuf,
 	PROGRAM_CNTXT_INIT(p, descbuf, 0);
 	phdr = SHR_HDR(p, share, hdr, 0);
 	__rta_copy_ipsec_encap_pdb(p, pdb, cipherdata->algtype);
-	COPY_DATA(p, pdb->ip_hdr, pdb->ip_hdr_len);
+
+	/* ip header if any follows the encap_pdb */
+	if (pdb->ip_hdr_len > 0) {
+		void *ip_hdr = pdb + 1;
+		COPY_DATA(p, ip_hdr, pdb->ip_hdr_len);
+	}
+
 	SET_LABEL(p, hdr);
 	pkeyjump = JUMP(p, keyjump, LOCAL_JUMP, ALL_TRUE, SHRD | SELF);
 	/*
Signature · 1 line
2.42.0
#82 lore raw

Re: [PATCH v5 10/10] common/dpaxx: replace zero length array

29/11/2023 03:39, Stephen Hemminger:

Quoted 1 line

+ * Ip header must follow directly after ipsec_encap_pdb

[...]

Quoted 2 lines
(quoted diff) +2 -0
+
+	/* ip header if any follows the encap_pdb */

[...]

Review

Quoted 1 line
(quoted diff) +1 -0
+	/* ip header if any follows the encap_pdb */

I would change "ip" to "IP".

#83 lore raw

Re: [PATCH v5 00/10] Replace zero length arrays

In reply to Stephen Hemminger

29/11/2023 03:39, Stephen Hemminger:

Quoted 10 lines

Zero length arrays are a GNU extension that has been superseded by flex arrays.

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

These are places found by cocci/zero_length_array.cocci

v5 - revised version of dpaxx ip_hdr fix

     rebase to 23.11
Quoted 11 lines

Stephen Hemminger (10):
member: replace zero length array with flex array
cryptodev: replace zero length array with flex array
security: replace zero length array with flex array
pipeline: replace zero length array with flex array net/nfp: replace zero length array with flex array net/enic: replace zero length array with flex array net/mlx5: replace zero length array with flex array
pdcp: replace zero length array with flex array net/cpfl: replace zero length array with flex array common/dpaxx: replace zero length array

There is no more left with
devtools/cocci.sh devtools/cocci/zero_length_array.cocci

Applied, thanks.