Commit b6ca09cb authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Saeed Mahameed

net/mlx5: Replace zero-length array with flexible-array

The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

sizeof(flexible-array-member) triggers a warning because flexible array
members have incomplete type[1]. There are some instances of code in
which the sizeof operator is being incorrectly/erroneously applied to
zero-length arrays and the result is zero. Such instances may be hiding
some bugs. So, this work (flexible-array member conversions) will also
help to get completely rid of those sorts of issues.

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent c6bc6041
......@@ -201,7 +201,7 @@ struct mlx5_rsc_debug {
void *object;
enum dbg_rsc_type type;
struct dentry *root;
struct mlx5_field_desc fields[0];
struct mlx5_field_desc fields[];
};
enum mlx5_dev_event {
......
......@@ -1703,7 +1703,7 @@ struct mlx5_ifc_wq_bits {
u8 reserved_at_140[0x4c0];
struct mlx5_ifc_cmd_pas_bits pas[0];
struct mlx5_ifc_cmd_pas_bits pas[];
};
struct mlx5_ifc_rq_num_bits {
......@@ -1921,7 +1921,7 @@ struct mlx5_ifc_resource_dump_menu_segment_bits {
u8 reserved_at_20[0x10];
u8 num_of_records[0x10];
struct mlx5_ifc_resource_dump_menu_record_bits record[0];
struct mlx5_ifc_resource_dump_menu_record_bits record[];
};
struct mlx5_ifc_resource_dump_resource_segment_bits {
......@@ -1933,7 +1933,7 @@ struct mlx5_ifc_resource_dump_resource_segment_bits {
u8 index2[0x20];
u8 payload[0][0x20];
u8 payload[][0x20];
};
struct mlx5_ifc_resource_dump_terminate_segment_bits {
......@@ -3010,7 +3010,7 @@ struct mlx5_ifc_flow_context_bits {
u8 reserved_at_1200[0x600];
union mlx5_ifc_dest_format_struct_flow_counter_list_auto_bits destination[0];
union mlx5_ifc_dest_format_struct_flow_counter_list_auto_bits destination[];
};
enum {
......@@ -3303,7 +3303,7 @@ struct mlx5_ifc_rqtc_bits {
u8 reserved_at_e0[0x6a0];
struct mlx5_ifc_rq_num_bits rq_num[0];
struct mlx5_ifc_rq_num_bits rq_num[];
};
enum {
......@@ -3415,7 +3415,7 @@ struct mlx5_ifc_nic_vport_context_bits {
u8 reserved_at_7e0[0x20];
u8 current_uc_mac_address[0][0x40];
u8 current_uc_mac_address[][0x40];
};
enum {
......@@ -4338,7 +4338,7 @@ struct mlx5_ifc_query_xrc_srq_out_bits {
u8 reserved_at_280[0x600];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_query_xrc_srq_in_bits {
......@@ -4616,7 +4616,7 @@ struct mlx5_ifc_query_srq_out_bits {
u8 reserved_at_280[0x600];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_query_srq_in_bits {
......@@ -4827,7 +4827,7 @@ struct mlx5_ifc_query_qp_out_bits {
u8 reserved_at_800[0x80];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_query_qp_in_bits {
......@@ -5160,7 +5160,7 @@ struct mlx5_ifc_query_hca_vport_pkey_out_bits {
u8 reserved_at_40[0x40];
struct mlx5_ifc_pkey_bits pkey[0];
struct mlx5_ifc_pkey_bits pkey[];
};
struct mlx5_ifc_query_hca_vport_pkey_in_bits {
......@@ -5196,7 +5196,7 @@ struct mlx5_ifc_query_hca_vport_gid_out_bits {
u8 gids_num[0x10];
u8 reserved_at_70[0x10];
struct mlx5_ifc_array128_auto_bits gid[0];
struct mlx5_ifc_array128_auto_bits gid[];
};
struct mlx5_ifc_query_hca_vport_gid_in_bits {
......@@ -5464,7 +5464,7 @@ struct mlx5_ifc_query_flow_counter_out_bits {
u8 reserved_at_40[0x40];
struct mlx5_ifc_traffic_counter_bits flow_statistics[0];
struct mlx5_ifc_traffic_counter_bits flow_statistics[];
};
struct mlx5_ifc_query_flow_counter_in_bits {
......@@ -5558,7 +5558,7 @@ struct mlx5_ifc_query_eq_out_bits {
u8 reserved_at_300[0x580];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_query_eq_in_bits {
......@@ -5583,7 +5583,7 @@ struct mlx5_ifc_packet_reformat_context_in_bits {
u8 reserved_at_20[0x10];
u8 reformat_data[2][0x8];
u8 more_reformat_data[0][0x8];
u8 more_reformat_data[][0x8];
};
struct mlx5_ifc_query_packet_reformat_context_out_bits {
......@@ -5594,7 +5594,7 @@ struct mlx5_ifc_query_packet_reformat_context_out_bits {
u8 reserved_at_40[0xa0];
struct mlx5_ifc_packet_reformat_context_in_bits packet_reformat_context[0];
struct mlx5_ifc_packet_reformat_context_in_bits packet_reformat_context[];
};
struct mlx5_ifc_query_packet_reformat_context_in_bits {
......@@ -5833,7 +5833,7 @@ struct mlx5_ifc_query_cq_out_bits {
u8 reserved_at_280[0x600];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_query_cq_in_bits {
......@@ -6440,7 +6440,7 @@ struct mlx5_ifc_modify_cq_in_bits {
u8 reserved_at_300[0x580];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_modify_cong_status_out_bits {
......@@ -6504,7 +6504,7 @@ struct mlx5_ifc_manage_pages_out_bits {
u8 reserved_at_60[0x20];
u8 pas[0][0x40];
u8 pas[][0x40];
};
enum {
......@@ -6526,7 +6526,7 @@ struct mlx5_ifc_manage_pages_in_bits {
u8 input_num_entries[0x20];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_mad_ifc_out_bits {
......@@ -7481,7 +7481,7 @@ struct mlx5_ifc_create_xrc_srq_in_bits {
u8 reserved_at_300[0x580];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_create_tis_out_bits {
......@@ -7557,7 +7557,7 @@ struct mlx5_ifc_create_srq_in_bits {
u8 reserved_at_280[0x600];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_create_sq_out_bits {
......@@ -7718,7 +7718,7 @@ struct mlx5_ifc_create_qp_in_bits {
u8 wq_umem_valid[0x1];
u8 reserved_at_861[0x1f];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_create_psv_out_bits {
......@@ -7789,7 +7789,7 @@ struct mlx5_ifc_create_mkey_in_bits {
u8 reserved_at_320[0x560];
u8 klm_pas_mtt[0][0x20];
u8 klm_pas_mtt[][0x20];
};
enum {
......@@ -7922,7 +7922,7 @@ struct mlx5_ifc_create_eq_in_bits {
u8 reserved_at_3c0[0x4c0];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_create_dct_out_bits {
......@@ -7979,7 +7979,7 @@ struct mlx5_ifc_create_cq_in_bits {
u8 cq_umem_valid[0x1];
u8 reserved_at_2e1[0x59f];
u8 pas[0][0x40];
u8 pas[][0x40];
};
struct mlx5_ifc_config_int_moderation_out_bits {
......@@ -8335,7 +8335,7 @@ struct mlx5_ifc_access_register_out_bits {
u8 reserved_at_40[0x40];
u8 register_data[0][0x20];
u8 register_data[][0x20];
};
enum {
......@@ -8355,7 +8355,7 @@ struct mlx5_ifc_access_register_in_bits {
u8 argument[0x20];
u8 register_data[0][0x20];
u8 register_data[][0x20];
};
struct mlx5_ifc_sltp_reg_bits {
......@@ -9372,7 +9372,7 @@ struct mlx5_ifc_cmd_in_bits {
u8 reserved_at_20[0x10];
u8 op_mod[0x10];
u8 command[0][0x20];
u8 command[][0x20];
};
struct mlx5_ifc_cmd_if_box_bits {
......@@ -9666,7 +9666,7 @@ struct mlx5_ifc_mcqi_reg_bits {
u8 reserved_at_a0[0x10];
u8 data_size[0x10];
union mlx5_ifc_mcqi_reg_data_bits data[0];
union mlx5_ifc_mcqi_reg_data_bits data[];
};
struct mlx5_ifc_mcc_reg_bits {
......@@ -10252,7 +10252,7 @@ struct mlx5_ifc_umem_bits {
u8 num_of_mtt[0x40];
struct mlx5_ifc_mtt_bits mtt[0];
struct mlx5_ifc_mtt_bits mtt[];
};
struct mlx5_ifc_uctx_bits {
......@@ -10377,7 +10377,7 @@ struct mlx5_ifc_mtrc_stdb_bits {
u8 reserved_at_4[0x4];
u8 read_size[0x18];
u8 start_offset[0x20];
u8 string_db_data[0];
u8 string_db_data[];
};
struct mlx5_ifc_mtrc_ctrl_bits {
......@@ -10431,7 +10431,7 @@ struct mlx5_ifc_query_esw_functions_out_bits {
struct mlx5_ifc_host_params_context_bits host_params_context;
u8 reserved_at_280[0x180];
u8 host_sf_enable[0][0x40];
u8 host_sf_enable[][0x40];
};
struct mlx5_ifc_sf_partition_bits {
......@@ -10451,7 +10451,7 @@ struct mlx5_ifc_query_sf_partitions_out_bits {
u8 reserved_at_60[0x20];
struct mlx5_ifc_sf_partition_bits sf_partition[0];
struct mlx5_ifc_sf_partition_bits sf_partition[];
};
struct mlx5_ifc_query_sf_partitions_in_bits {
......
......@@ -408,7 +408,7 @@ struct mlx5_wqe_signature_seg {
struct mlx5_wqe_inline_seg {
__be32 byte_count;
__be32 data[0];
__be32 data[];
};
enum mlx5_sig_type {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment