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] https://github.com/KSPP/linux/issues/21
[3] commit 7649773293
("cxgb3/l2t: Fix undefined behaviour")
Link: https://lore.kernel.org/r/20200213010425.GA13068@embeddedor.com
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> # added a few more
This commit is contained in:

committed by
Jason Gunthorpe

parent
52c5e9e749
commit
5b361328ca
@@ -73,7 +73,7 @@ struct ib_pool_fmr {
|
||||
int remap_count;
|
||||
u64 io_virtual_address;
|
||||
int page_list_len;
|
||||
u64 page_list[0];
|
||||
u64 page_list[];
|
||||
};
|
||||
|
||||
struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
|
||||
|
@@ -1876,7 +1876,7 @@ struct ib_flow_eth_filter {
|
||||
__be16 ether_type;
|
||||
__be16 vlan_tag;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_eth {
|
||||
@@ -1890,7 +1890,7 @@ struct ib_flow_ib_filter {
|
||||
__be16 dlid;
|
||||
__u8 sl;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_ib {
|
||||
@@ -1915,7 +1915,7 @@ struct ib_flow_ipv4_filter {
|
||||
u8 ttl;
|
||||
u8 flags;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_ipv4 {
|
||||
@@ -1933,7 +1933,7 @@ struct ib_flow_ipv6_filter {
|
||||
u8 traffic_class;
|
||||
u8 hop_limit;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_ipv6 {
|
||||
@@ -1947,7 +1947,7 @@ struct ib_flow_tcp_udp_filter {
|
||||
__be16 dst_port;
|
||||
__be16 src_port;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_tcp_udp {
|
||||
@@ -1959,7 +1959,7 @@ struct ib_flow_spec_tcp_udp {
|
||||
|
||||
struct ib_flow_tunnel_filter {
|
||||
__be32 tunnel_id;
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
/* ib_flow_spec_tunnel describes the Vxlan tunnel
|
||||
@@ -1976,7 +1976,7 @@ struct ib_flow_esp_filter {
|
||||
__be32 spi;
|
||||
__be32 seq;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_esp {
|
||||
@@ -1991,7 +1991,7 @@ struct ib_flow_gre_filter {
|
||||
__be16 protocol;
|
||||
__be32 key;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_gre {
|
||||
@@ -2004,7 +2004,7 @@ struct ib_flow_spec_gre {
|
||||
struct ib_flow_mpls_filter {
|
||||
__be32 tag;
|
||||
/* Must be last */
|
||||
u8 real_sz[0];
|
||||
u8 real_sz[];
|
||||
};
|
||||
|
||||
struct ib_flow_spec_mpls {
|
||||
|
@@ -75,7 +75,7 @@
|
||||
struct opa_vnic_rdma_netdev {
|
||||
struct rdma_netdev rn; /* keep this first */
|
||||
/* followed by device private data */
|
||||
char *dev_priv[0];
|
||||
char *dev_priv[];
|
||||
};
|
||||
|
||||
static inline void *opa_vnic_priv(const struct net_device *dev)
|
||||
|
@@ -85,7 +85,7 @@ struct rvt_mregion {
|
||||
u8 lkey_published; /* in global table */
|
||||
struct percpu_ref refcount;
|
||||
struct completion comp; /* complete when refcount goes to zero */
|
||||
struct rvt_segarray *map[0]; /* the segments */
|
||||
struct rvt_segarray *map[]; /* the segments */
|
||||
};
|
||||
|
||||
#define RVT_MAX_LKEY_TABLE_BITS 23
|
||||
|
@@ -191,7 +191,7 @@ struct rvt_swqe {
|
||||
u32 ssn; /* send sequence number */
|
||||
u32 length; /* total length of data in sg_list */
|
||||
void *priv; /* driver dependent field */
|
||||
struct rvt_sge sg_list[0];
|
||||
struct rvt_sge sg_list[];
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user