Skip to content

Commit 5b36132

Browse files
GustavoARSilvajgunthorpe
authored andcommitted
RDMA: Replace zero-length array with flexible-array member
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] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] KSPP/linux#21 [3] commit 7649773 ("cxgb3/l2t: Fix undefined behaviour") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> # added a few more
1 parent 52c5e9e commit 5b36132

File tree

25 files changed

+44
-44
lines changed

25 files changed

+44
-44
lines changed

drivers/infiniband/core/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
struct ib_pkey_cache {
4848
int table_len;
49-
u16 table[0];
49+
u16 table[];
5050
};
5151

5252
struct ib_update_work {

drivers/infiniband/core/cm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ struct cm_device {
197197
struct ib_device *ib_device;
198198
u8 ack_delay;
199199
int going_down;
200-
struct cm_port *port[0];
200+
struct cm_port *port[];
201201
};
202202

203203
struct cm_av {
@@ -216,7 +216,7 @@ struct cm_work {
216216
__be32 local_id; /* Established / timewait */
217217
__be32 remote_id;
218218
struct ib_cm_event cm_event;
219-
struct sa_path_rec path[0];
219+
struct sa_path_rec path[];
220220
};
221221

222222
struct cm_timewait_info {

drivers/infiniband/core/mad_priv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ struct ib_mad_private {
7979
struct ib_mad_private_header header;
8080
size_t mad_size;
8181
struct ib_grh grh;
82-
u8 mad[0];
82+
u8 mad[];
8383
} __packed;
8484

8585
struct ib_rmpp_segment {
8686
struct list_head list;
8787
u32 num;
88-
u8 data[0];
88+
u8 data[];
8989
};
9090

9191
struct ib_mad_agent_private {

drivers/infiniband/core/multicast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct mcast_device {
7171
struct ib_event_handler event_handler;
7272
int start_port;
7373
int end_port;
74-
struct mcast_port port[0];
74+
struct mcast_port port[];
7575
};
7676

7777
enum mcast_state {

drivers/infiniband/core/sa_query.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct ib_sa_port {
101101
struct ib_sa_device {
102102
int start_port, end_port;
103103
struct ib_event_handler event_handler;
104-
struct ib_sa_port port[0];
104+
struct ib_sa_port port[];
105105
};
106106

107107
struct ib_sa_query {

drivers/infiniband/hw/cxgb4/iw_cxgb4.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ struct mpa_message {
707707
u8 flags;
708708
u8 revision;
709709
__be16 private_data_size;
710-
u8 private_data[0];
710+
u8 private_data[];
711711
};
712712

713713
struct mpa_v2_conn_params {
@@ -719,7 +719,7 @@ struct terminate_message {
719719
u8 layer_etype;
720720
u8 ecode;
721721
__be16 hdrct_rsvd;
722-
u8 len_hdrs[0];
722+
u8 len_hdrs[];
723723
};
724724

725725
#define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)

drivers/infiniband/hw/cxgb4/t4fw_ri_api.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct fw_ri_dsgl {
123123
__be32 len0;
124124
__be64 addr0;
125125
#ifndef C99_NOT_SUPPORTED
126-
struct fw_ri_dsge_pair sge[0];
126+
struct fw_ri_dsge_pair sge[];
127127
#endif
128128
};
129129

@@ -139,7 +139,7 @@ struct fw_ri_isgl {
139139
__be16 nsge;
140140
__be32 r2;
141141
#ifndef C99_NOT_SUPPORTED
142-
struct fw_ri_sge sge[0];
142+
struct fw_ri_sge sge[];
143143
#endif
144144
};
145145

@@ -149,7 +149,7 @@ struct fw_ri_immd {
149149
__be16 r2;
150150
__be32 immdlen;
151151
#ifndef C99_NOT_SUPPORTED
152-
__u8 data[0];
152+
__u8 data[];
153153
#endif
154154
};
155155

@@ -321,7 +321,7 @@ struct fw_ri_res_wr {
321321
__be32 len16_pkd;
322322
__u64 cookie;
323323
#ifndef C99_NOT_SUPPORTED
324-
struct fw_ri_res res[0];
324+
struct fw_ri_res res[];
325325
#endif
326326
};
327327

drivers/infiniband/hw/hfi1/mad.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ struct opa_port_status_rsp {
23812381
__be64 port_vl_rcv_bubble;
23822382
__be64 port_vl_mark_fecn;
23832383
__be64 port_vl_xmit_discards;
2384-
} vls[0]; /* real array size defined by # bits set in vl_select_mask */
2384+
} vls[]; /* real array size defined by # bits set in vl_select_mask */
23852385
};
23862386

23872387
enum counter_selects {
@@ -2423,7 +2423,7 @@ struct opa_aggregate {
24232423
__be16 attr_id;
24242424
__be16 err_reqlength; /* 1 bit, 8 res, 7 bit */
24252425
__be32 attr_mod;
2426-
u8 data[0];
2426+
u8 data[];
24272427
};
24282428

24292429
#define MSK_LLI 0x000000f0

drivers/infiniband/hw/hfi1/mad.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct opa_mad_notice_attr {
165165
} __packed ntc_2048;
166166

167167
};
168-
u8 class_data[0];
168+
u8 class_data[];
169169
};
170170

171171
#define IB_VLARB_LOWPRI_0_31 1

drivers/infiniband/hw/hfi1/pio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ struct sc_config_sizes {
243243
*/
244244
struct pio_map_elem {
245245
u32 mask;
246-
struct send_context *ksc[0];
246+
struct send_context *ksc[];
247247
};
248248

249249
/*
@@ -263,7 +263,7 @@ struct pio_vl_map {
263263
u32 mask;
264264
u8 actual_vls;
265265
u8 vls;
266-
struct pio_map_elem *map[0];
266+
struct pio_map_elem *map[];
267267
};
268268

269269
int pio_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls,

drivers/infiniband/hw/hfi1/sdma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ struct sdma_engine *sdma_select_engine_sc(
833833
struct sdma_rht_map_elem {
834834
u32 mask;
835835
u8 ctr;
836-
struct sdma_engine *sde[0];
836+
struct sdma_engine *sde[];
837837
};
838838

839839
struct sdma_rht_node {

drivers/infiniband/hw/hfi1/sdma.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ void sdma_engine_interrupt(struct sdma_engine *sde, u64 status);
10021002
*/
10031003
struct sdma_map_elem {
10041004
u32 mask;
1005-
struct sdma_engine *sde[0];
1005+
struct sdma_engine *sde[];
10061006
};
10071007

10081008
/**
@@ -1024,7 +1024,7 @@ struct sdma_vl_map {
10241024
u32 mask;
10251025
u8 actual_vls;
10261026
u8 vls;
1027-
struct sdma_map_elem *map[0];
1027+
struct sdma_map_elem *map[];
10281028
};
10291029

10301030
int sdma_map_init(

drivers/infiniband/hw/hfi1/user_exp_rcv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct tid_rb_node {
7373
dma_addr_t dma_addr;
7474
bool freed;
7575
unsigned int npages;
76-
struct page *pages[0];
76+
struct page *pages[];
7777
};
7878

7979
static inline int num_user_pages(unsigned long addr,

drivers/infiniband/hw/i40iw/i40iw_cm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct ietf_mpa_v1 {
8585
u8 flags;
8686
u8 rev;
8787
__be16 priv_data_len;
88-
u8 priv_data[0];
88+
u8 priv_data[];
8989
};
9090

9191
#define ietf_mpa_req_resp_frame ietf_mpa_frame
@@ -101,7 +101,7 @@ struct ietf_mpa_v2 {
101101
u8 rev;
102102
__be16 priv_data_len;
103103
struct ietf_rtr_msg rtr_msg;
104-
u8 priv_data[0];
104+
u8 priv_data[];
105105
};
106106

107107
struct i40iw_cm_node;

drivers/infiniband/hw/mthca/mthca_memfree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct mthca_user_db_table {
5858
u64 uvirt;
5959
struct scatterlist mem;
6060
int refcount;
61-
} page[0];
61+
} page[];
6262
};
6363

6464
static void mthca_free_icm_pages(struct mthca_dev *dev, struct mthca_icm_chunk *chunk)

drivers/infiniband/hw/mthca/mthca_memfree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct mthca_icm_table {
6868
int lowmem;
6969
int coherent;
7070
struct mutex mutex;
71-
struct mthca_icm *icm[0];
71+
struct mthca_icm *icm[];
7272
};
7373

7474
struct mthca_icm_iter {

drivers/infiniband/hw/usnic/usnic_uiom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct usnic_uiom_reg {
7777
struct usnic_uiom_chunk {
7878
struct list_head list;
7979
int nents;
80-
struct scatterlist page_list[0];
80+
struct scatterlist page_list[];
8181
};
8282

8383
struct usnic_uiom_pd *usnic_uiom_alloc_pd(void);

drivers/infiniband/sw/rxe/rxe_queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct rxe_queue_buf {
6363
__u32 pad_2[31];
6464
__u32 consumer_index;
6565
__u32 pad_3[31];
66-
__u8 data[0];
66+
__u8 data[];
6767
};
6868

6969
struct rxe_queue {

drivers/infiniband/ulp/opa_vnic/opa_vnic_encap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct opa_veswport_mactable {
258258
__be16 offset;
259259
__be16 num_entries;
260260
__be32 mac_tbl_digest;
261-
struct opa_veswport_mactable_entry tbl_entries[0];
261+
struct opa_veswport_mactable_entry tbl_entries[];
262262
} __packed;
263263

264264
/**
@@ -440,7 +440,7 @@ struct opa_veswport_iface_macs {
440440
__be16 num_macs_in_msg;
441441
__be16 tot_macs_in_lst;
442442
__be16 gen_count;
443-
struct opa_vnic_iface_mac_entry entry[0];
443+
struct opa_vnic_iface_mac_entry entry[];
444444
} __packed;
445445

446446
/**

drivers/infiniband/ulp/srp/ib_srp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ struct srp_fr_pool {
309309
int max_page_list_len;
310310
spinlock_t lock;
311311
struct list_head free_list;
312-
struct srp_fr_desc desc[0];
312+
struct srp_fr_desc desc[];
313313
};
314314

315315
/**

include/rdma/ib_fmr_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct ib_pool_fmr {
7373
int remap_count;
7474
u64 io_virtual_address;
7575
int page_list_len;
76-
u64 page_list[0];
76+
u64 page_list[];
7777
};
7878

7979
struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,

include/rdma/ib_verbs.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ struct ib_flow_eth_filter {
18761876
__be16 ether_type;
18771877
__be16 vlan_tag;
18781878
/* Must be last */
1879-
u8 real_sz[0];
1879+
u8 real_sz[];
18801880
};
18811881

18821882
struct ib_flow_spec_eth {
@@ -1890,7 +1890,7 @@ struct ib_flow_ib_filter {
18901890
__be16 dlid;
18911891
__u8 sl;
18921892
/* Must be last */
1893-
u8 real_sz[0];
1893+
u8 real_sz[];
18941894
};
18951895

18961896
struct ib_flow_spec_ib {
@@ -1915,7 +1915,7 @@ struct ib_flow_ipv4_filter {
19151915
u8 ttl;
19161916
u8 flags;
19171917
/* Must be last */
1918-
u8 real_sz[0];
1918+
u8 real_sz[];
19191919
};
19201920

19211921
struct ib_flow_spec_ipv4 {
@@ -1933,7 +1933,7 @@ struct ib_flow_ipv6_filter {
19331933
u8 traffic_class;
19341934
u8 hop_limit;
19351935
/* Must be last */
1936-
u8 real_sz[0];
1936+
u8 real_sz[];
19371937
};
19381938

19391939
struct ib_flow_spec_ipv6 {
@@ -1947,7 +1947,7 @@ struct ib_flow_tcp_udp_filter {
19471947
__be16 dst_port;
19481948
__be16 src_port;
19491949
/* Must be last */
1950-
u8 real_sz[0];
1950+
u8 real_sz[];
19511951
};
19521952

19531953
struct ib_flow_spec_tcp_udp {
@@ -1959,7 +1959,7 @@ struct ib_flow_spec_tcp_udp {
19591959

19601960
struct ib_flow_tunnel_filter {
19611961
__be32 tunnel_id;
1962-
u8 real_sz[0];
1962+
u8 real_sz[];
19631963
};
19641964

19651965
/* ib_flow_spec_tunnel describes the Vxlan tunnel
@@ -1976,7 +1976,7 @@ struct ib_flow_esp_filter {
19761976
__be32 spi;
19771977
__be32 seq;
19781978
/* Must be last */
1979-
u8 real_sz[0];
1979+
u8 real_sz[];
19801980
};
19811981

19821982
struct ib_flow_spec_esp {
@@ -1991,7 +1991,7 @@ struct ib_flow_gre_filter {
19911991
__be16 protocol;
19921992
__be32 key;
19931993
/* Must be last */
1994-
u8 real_sz[0];
1994+
u8 real_sz[];
19951995
};
19961996

19971997
struct ib_flow_spec_gre {
@@ -2004,7 +2004,7 @@ struct ib_flow_spec_gre {
20042004
struct ib_flow_mpls_filter {
20052005
__be32 tag;
20062006
/* Must be last */
2007-
u8 real_sz[0];
2007+
u8 real_sz[];
20082008
};
20092009

20102010
struct ib_flow_spec_mpls {

include/rdma/opa_vnic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
struct opa_vnic_rdma_netdev {
7676
struct rdma_netdev rn; /* keep this first */
7777
/* followed by device private data */
78-
char *dev_priv[0];
78+
char *dev_priv[];
7979
};
8080

8181
static inline void *opa_vnic_priv(const struct net_device *dev)

include/rdma/rdmavt_mr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct rvt_mregion {
8585
u8 lkey_published; /* in global table */
8686
struct percpu_ref refcount;
8787
struct completion comp; /* complete when refcount goes to zero */
88-
struct rvt_segarray *map[0]; /* the segments */
88+
struct rvt_segarray *map[]; /* the segments */
8989
};
9090

9191
#define RVT_MAX_LKEY_TABLE_BITS 23

include/rdma/rdmavt_qp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct rvt_swqe {
191191
u32 ssn; /* send sequence number */
192192
u32 length; /* total length of data in sg_list */
193193
void *priv; /* driver dependent field */
194-
struct rvt_sge sg_list[0];
194+
struct rvt_sge sg_list[];
195195
};
196196

197197
/**

0 commit comments

Comments
 (0)