Subject: Re: [PATCH] mlxsw: spectrum_router: Replace 0-length array with flexible array

From: Petr Machata <[email-masked]>
Date: Fri, 6 Jan 2023 11:02:11 +0100

Kees Cook <[email-masked]> writes:

> Zero-length arrays are deprecated[1]. Replace struct
> mlxsw_sp_nexthop_group_info's "nexthops" 0-length array with a flexible
> array. Detected with GCC 13, using -fstrict-flex-arrays=3:
>
> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_nexthop_group_hash_obj':
> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:3278:38: warning: array subscript i is outside array bounds of 'struct mlxsw_sp_nexthop[0]' [-Warray-bounds=]
>  3278 |                         val ^= jhash(&nh->ifindex, sizeof(nh->ifindex), seed);
>       |                                      ^~~~~~~~~~~~
> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:2954:33: note: while referencing 'nexthops'
>  2954 |         struct mlxsw_sp_nexthop nexthops[0];
>       |                                 ^~~~~~~~
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
>
> Cc: Ido Schimmel <[email-masked]>
> Cc: Petr Machata <[email-masked]>
> Cc: "David S. Miller" <[email-masked]>
> Cc: Eric Dumazet <[email-masked]>
> Cc: Jakub Kicinski <[email-masked]>
> Cc: Paolo Abeni <[email-masked]>
> Cc: "Gustavo A. R. Silva" <[email-masked]>
> Cc: [email-masked]
> Signed-off-by: Kees Cook <[email-masked]>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
> index c22c3ac4e2a1..09e32778b012 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
> @@ -2951,7 +2951,7 @@ struct mlxsw_sp_nexthop_group_info {
>  	   gateway:1, /* routes using the group use a gateway */
>  	   is_resilient:1;
>  	struct list_head list; /* member in nh_res_grp_list */
> -	struct mlxsw_sp_nexthop nexthops[0];
> +	struct mlxsw_sp_nexthop nexthops[];
>  #define nh_rif	nexthops[0].rif
>  };

Thanks. I'll pass this through our nightly and report back.