[PATCH v5 16/21] drivers: add flex array support and fix issues

Hore, Soumyadeep soumyadeep.hore at intel.com
Mon Jul 1 12:09:30 CEST 2024


> With the internal Linux upstream feedback that is received on IDPF 
> driver and also some references available online, it is discouraged to 
> use 1-sized array fields in the structures, especially in the new 
> Linux drivers that are going to be upstreamed. Instead, it is 
> recommended to use flex array fields for the dynamic sized structures.
> 
> Some fixes based on code change is introduced to compile dpdk.
> 
> Signed-off-by: Soumyadeep Hore <soumyadeep.hore at intel.com>
> ---
>  drivers/common/idpf/base/virtchnl2.h       | 466 ++++-----------------
>  drivers/common/idpf/idpf_common_virtchnl.c |   2 +-
>  drivers/net/cpfl/cpfl_ethdev.c             |  28 +-
>  3 files changed, 86 insertions(+), 410 deletions(-)
> 
> diff --git a/drivers/common/idpf/base/virtchnl2.h 
> b/drivers/common/idpf/base/virtchnl2.h
> index 9dd5191c0e..317bd06c0f 100644
> --- a/drivers/common/idpf/base/virtchnl2.h
> +++ b/drivers/common/idpf/base/virtchnl2.h
> @@ -63,6 +63,10 @@ enum virtchnl2_status {
>  #define VIRTCHNL2_CHECK_STRUCT_LEN(n, X)	\
>  	static_assert((n) == sizeof(struct X),	\
>  		      "Structure length does not match with the expected value")
> +#define VIRTCHNL2_CHECK_STRUCT_VAR_LEN(n, X, T)		\
> +	VIRTCHNL2_CHECK_STRUCT_LEN(n, X)
> +
> +#define STRUCT_VAR_LEN		1
>  
>  /**
>   * New major set of opcodes introduced and so leaving room for @@ 
> -696,10 +700,9 @@ VIRTCHNL2_CHECK_STRUCT_LEN(32, 
> virtchnl2_queue_reg_chunk);  struct virtchnl2_queue_reg_chunks {
>  	__le16 num_chunks;
>  	u8 pad[6];
> -	struct virtchnl2_queue_reg_chunk chunks[1];
> +	struct virtchnl2_queue_reg_chunk chunks[STRUCT_VAR_LEN];
>  };

This patch doesn't actually seem to be using flexible array members.
Instead I see a macro with value "1" being used in place of a hard-coded "1". Can you please check that commit message matches what's actually happening, and that changes in the patch are correct.

Thanks,
/Bruce

Addressed in v6 by adding the corresponding commit message.

Regards,
Soumya


More information about the dev mailing list