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

Message ID 20230113215205.125767-5-stephen@networkplumber.org (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series replace zero length arrays |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Stephen Hemminger Jan. 13, 2023, 9:52 p.m. UTC
  Zero length arrays are GNU extension. Replace with
standard flex array.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 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(-)
  

Comments

Stephen Hemminger Jan. 14, 2023, 5:08 p.m. UTC | #1
On Fri, 13 Jan 2023 13:52:02 -0800
Stephen Hemminger <stephen@networkplumber.org> wrote:

> Zero length arrays are GNU extension. Replace with
> standard flex array.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---


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.
  
Slava Ovsiienko March 6, 2023, 1:29 p.m. UTC | #2
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

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: суббота, 14 января 2023 г. 19:08
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>
> Subject: Re: [PATCH 4/7] mlx5: replace zero length array with flex array
> 
> On Fri, 13 Jan 2023 13:52:02 -0800
> Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> > Zero length arrays are GNU extension. Replace with standard flex
> > array.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> 
> 
> 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.
  

Patch

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 31982002ee9b..2b295f9ba037 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -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
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 1f57ecd6e1c1..e12efab211d2 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -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
diff --git a/drivers/net/mlx5/mlx5_tx.h b/drivers/net/mlx5/mlx5_tx.h
index a44050a1cec3..d026e8126a75 100644
--- a/drivers/net/mlx5/mlx5_tx.h
+++ b/drivers/net/mlx5/mlx5_tx.h
@@ -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;