Re: [PATCH 1/4][next] i40e: Replace one-element array with flex-array member in struct i40e_package_header

From: Simon Horman
Date: Wed Aug 02 2023 - 11:24:17 EST


On Tue, Aug 01, 2023 at 11:05:31PM -0600, Gustavo A. R. Silva wrote:
> One-element and zero-length arrays are deprecated. So, replace
> one-element array in struct i40e_package_header with flexible-array
> member.
>
> The `+ sizeof(u32)` adjustments ensure that there are no differences
> in binary output.
>
> Link: https://github.com/KSPP/linux/issues/335
> Signed-off-by: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx>
> ---
> drivers/net/ethernet/intel/i40e/i40e_ddp.c | 4 ++--
> drivers/net/ethernet/intel/i40e/i40e_type.h | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_ddp.c b/drivers/net/ethernet/intel/i40e/i40e_ddp.c
> index 7e8183762fd9..0db6f5e3cfcc 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_ddp.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_ddp.c
> @@ -220,7 +220,7 @@ static bool i40e_ddp_is_pkg_hdr_valid(struct net_device *netdev,
> netdev_err(netdev, "Invalid DDP profile - size is bigger than 4G");
> return false;
> }
> - if (size < (sizeof(struct i40e_package_header) +
> + if (size < (sizeof(struct i40e_package_header) + sizeof(u32) +

Hi Gustavo,

would it make more sense to use struct_size() here?

> sizeof(struct i40e_metadata_segment) + sizeof(u32) * 2)) {
> netdev_err(netdev, "Invalid DDP profile - size is too small.");
> return false;
> @@ -281,7 +281,7 @@ int i40e_ddp_load(struct net_device *netdev, const u8 *data, size_t size,
> if (!i40e_ddp_is_pkg_hdr_valid(netdev, pkg_hdr, size))
> return -EINVAL;
>
> - if (size < (sizeof(struct i40e_package_header) +
> + if (size < (sizeof(struct i40e_package_header) + sizeof(u32) +
> sizeof(struct i40e_metadata_segment) + sizeof(u32) * 2)) {
> netdev_err(netdev, "Invalid DDP recipe size.");
> return -EINVAL;
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_type.h b/drivers/net/ethernet/intel/i40e/i40e_type.h
> index 388c3d36d96a..c3d5fe12059a 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_type.h
> +++ b/drivers/net/ethernet/intel/i40e/i40e_type.h
> @@ -1456,7 +1456,7 @@ struct i40e_ddp_version {
> struct i40e_package_header {
> struct i40e_ddp_version version;
> u32 segment_count;
> - u32 segment_offset[1];
> + u32 segment_offset[];
> };
>
> /* Generic segment header */
> --
> 2.34.1
>
>