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
@@ -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 {
|
||||
|
Reference in New Issue
Block a user