2023-01-05 23:26:56

by Kees Cook

[permalink] [raw]
Subject: [PATCH] net/mlx5e: Replace 0-length array with flexible array

Zero-length arrays are deprecated[1]. Replace struct mlx5e_rx_wqe_cyc's
"data" 0-length array with a flexible array. Detected with GCC 13,
using -fstrict-flex-arrays=3:

drivers/net/ethernet/mellanox/mlx5/core/en_main.c: In function 'mlx5e_alloc_rq':
drivers/net/ethernet/mellanox/mlx5/core/en_main.c:827:42: warning: array subscript f is outside array bounds of 'struct mlx5_wqe_data_seg[0]' [-Warray-bounds=]
827 | wqe->data[f].byte_count = 0;
| ~~~~~~~~~^~~
In file included from drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h:11,
from drivers/net/ethernet/mellanox/mlx5/core/eswitch.h:48,
from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:42:
drivers/net/ethernet/mellanox/mlx5/core/en.h:250:39: note: while referencing 'data'
250 | struct mlx5_wqe_data_seg data[0];
| ^~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc: Saeed Mahameed <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 2d77fb8a8a01..37cf3b1bb144 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -247,7 +247,7 @@ struct mlx5e_rx_wqe_ll {
};

struct mlx5e_rx_wqe_cyc {
- struct mlx5_wqe_data_seg data[0];
+ DECLARE_FLEX_ARRAY(struct mlx5_wqe_data_seg, data);
};

struct mlx5e_umr_wqe {
--
2.34.1


2023-01-06 16:51:24

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH] net/mlx5e: Replace 0-length array with flexible array

On Thu, Jan 05, 2023 at 02:36:43PM -0800, Kees Cook wrote:
> Zero-length arrays are deprecated[1]. Replace struct mlx5e_rx_wqe_cyc's
> "data" 0-length array with a flexible array. Detected with GCC 13,
> using -fstrict-flex-arrays=3:
>
> drivers/net/ethernet/mellanox/mlx5/core/en_main.c: In function 'mlx5e_alloc_rq':
> drivers/net/ethernet/mellanox/mlx5/core/en_main.c:827:42: warning: array subscript f is outside array bounds of 'struct mlx5_wqe_data_seg[0]' [-Warray-bounds=]
> 827 | wqe->data[f].byte_count = 0;
> | ~~~~~~~~~^~~
> In file included from drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h:11,
> from drivers/net/ethernet/mellanox/mlx5/core/eswitch.h:48,
> from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:42:
> drivers/net/ethernet/mellanox/mlx5/core/en.h:250:39: note: while referencing 'data'
> 250 | struct mlx5_wqe_data_seg data[0];
> | ^~~~
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
>
> Cc: Saeed Mahameed <[email protected]>
> Cc: Leon Romanovsky <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: Eric Dumazet <[email protected]>
> Cc: Jakub Kicinski <[email protected]>
> Cc: Paolo Abeni <[email protected]>
> Cc: "Gustavo A. R. Silva" <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>

Reviewed-by: Gustavo A. R. Silva <[email protected]>

Thanks!
--
Gustavo

> ---
> drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
> index 2d77fb8a8a01..37cf3b1bb144 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
> @@ -247,7 +247,7 @@ struct mlx5e_rx_wqe_ll {
> };
>
> struct mlx5e_rx_wqe_cyc {
> - struct mlx5_wqe_data_seg data[0];
> + DECLARE_FLEX_ARRAY(struct mlx5_wqe_data_seg, data);
> };
>
> struct mlx5e_umr_wqe {
> --
> 2.34.1
>

2023-01-10 17:17:19

by Jiri Pirko

[permalink] [raw]
Subject: Re: [PATCH] net/mlx5e: Replace 0-length array with flexible array

Thu, Jan 05, 2023 at 11:36:43PM CET, [email protected] wrote:
>Zero-length arrays are deprecated[1]. Replace struct mlx5e_rx_wqe_cyc's
>"data" 0-length array with a flexible array. Detected with GCC 13,
>using -fstrict-flex-arrays=3:
>
>drivers/net/ethernet/mellanox/mlx5/core/en_main.c: In function 'mlx5e_alloc_rq':
>drivers/net/ethernet/mellanox/mlx5/core/en_main.c:827:42: warning: array subscript f is outside array bounds of 'struct mlx5_wqe_data_seg[0]' [-Warray-bounds=]
> 827 | wqe->data[f].byte_count = 0;
> | ~~~~~~~~~^~~
>In file included from drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h:11,
> from drivers/net/ethernet/mellanox/mlx5/core/eswitch.h:48,
> from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:42:
>drivers/net/ethernet/mellanox/mlx5/core/en.h:250:39: note: while referencing 'data'
> 250 | struct mlx5_wqe_data_seg data[0];
> | ^~~~
>
>[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
>
>Cc: Saeed Mahameed <[email protected]>
>Cc: Leon Romanovsky <[email protected]>
>Cc: "David S. Miller" <[email protected]>
>Cc: Eric Dumazet <[email protected]>
>Cc: Jakub Kicinski <[email protected]>
>Cc: Paolo Abeni <[email protected]>
>Cc: "Gustavo A. R. Silva" <[email protected]>
>Cc: [email protected]
>Cc: [email protected]
>Signed-off-by: Kees Cook <[email protected]>


Reviewed-by: Jiri Pirko <[email protected]>

2023-01-10 22:47:19

by Saeed Mahameed

[permalink] [raw]
Subject: Re: [PATCH] net/mlx5e: Replace 0-length array with flexible array

On 05 Jan 14:36, Kees Cook wrote:
>Zero-length arrays are deprecated[1]. Replace struct mlx5e_rx_wqe_cyc's
>"data" 0-length array with a flexible array. Detected with GCC 13,
>using -fstrict-flex-arrays=3:
>
>drivers/net/ethernet/mellanox/mlx5/core/en_main.c: In function 'mlx5e_alloc_rq':
>drivers/net/ethernet/mellanox/mlx5/core/en_main.c:827:42: warning: array subscript f is outside array bounds of 'struct mlx5_wqe_data_seg[0]' [-Warray-bounds=]
> 827 | wqe->data[f].byte_count = 0;
> | ~~~~~~~~~^~~
>In file included from drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h:11,
> from drivers/net/ethernet/mellanox/mlx5/core/eswitch.h:48,
> from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:42:
>drivers/net/ethernet/mellanox/mlx5/core/en.h:250:39: note: while referencing 'data'
> 250 | struct mlx5_wqe_data_seg data[0];
> | ^~~~
>
>[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
>
>Cc: Saeed Mahameed <[email protected]>
>Cc: Leon Romanovsky <[email protected]>
>Cc: "David S. Miller" <[email protected]>
>Cc: Eric Dumazet <[email protected]>
>Cc: Jakub Kicinski <[email protected]>
>Cc: Paolo Abeni <[email protected]>
>Cc: "Gustavo A. R. Silva" <[email protected]>
>Cc: [email protected]
>Cc: [email protected]
>Signed-off-by: Kees Cook <[email protected]>

Applied to net-next-mlx5, Thanks!