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

Message ID 20231129024221.57653-8-stephen@networkplumber.org (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers
Series Replace zero length arrays |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Nov. 29, 2023, 2:39 a.m. UTC
  Zero length arrays are GNU extension. Replace with
standard flex array.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
---
 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(-)
  

Comments

Thomas Monjalon Jan. 23, 2024, 9:44 a.m. UTC | #1
29/11/2023 03:39, Stephen Hemminger:
> --- a/drivers/net/mlx5/mlx5_tx.h
> +++ b/drivers/net/mlx5/mlx5_tx.h
> @@ -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 {

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.
  
Thomas Monjalon Jan. 23, 2024, 10:28 a.m. UTC | #2
23/01/2024 10:44, Thomas Monjalon:
> 29/11/2023 03:39, Stephen Hemminger:
> > --- a/drivers/net/mlx5/mlx5_tx.h
> > +++ b/drivers/net/mlx5/mlx5_tx.h
> > @@ -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 {
> 
> 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?
  
Dariusz Sosnowski Jan. 23, 2024, 11:18 a.m. UTC | #3
From: Thomas Monjalon <thomas@monjalon.net>
Sent: Tuesday, January 23, 2024 11:28
> 23/01/2024 10:44, Thomas Monjalon:
> > 29/11/2023 03:39, Stephen Hemminger:
> > > --- a/drivers/net/mlx5/mlx5_tx.h
> > > +++ b/drivers/net/mlx5/mlx5_tx.h
> > > @@ -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 {
> >
> > 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?

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
  

Patch

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index 9e22dce6da13..932b89bd79d3 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -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 {
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 263ebead7f29..f2e2e04429d1 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -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
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 6dde9de688b9..b35079b30a6e 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -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
diff --git a/drivers/net/mlx5/mlx5_tx.h b/drivers/net/mlx5/mlx5_tx.h
index e59ce37667ba..b1e8ea19a2a1 100644
--- a/drivers/net/mlx5/mlx5_tx.h
+++ b/drivers/net/mlx5/mlx5_tx.h
@@ -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. */