Skip to content

Commit ee4acc5

Browse files
GustavoARSilvakees
authored andcommitted
nfp: tls: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. So, in order to avoid ending up with flexible-array members in the middle of other structs, we use the `struct_group_tagged()` helper to separate the flexible array from the rest of the members in the flexible structure. We then use the newly created tagged `struct nfp_crypto_req_add_front_hdr` to replace the type of the objects causing trouble in a couple of structures. We also want to ensure that when new members need to be added to the flexible structure, they are always included within the newly created tagged struct. For this, we use `static_assert()`. This ensures that the memory layout for both the flexible structure and the new tagged struct is the same after any changes. Lastly, use container_of() to retrieve a pointer to the flexible structure and, through that, access the flexible-array member when needed. So, with these changes, fix the following warnings: drivers/net/ethernet/netronome/nfp/nfd3/../crypto/fw.h:58:41: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/net/ethernet/netronome/nfp/nfd3/../crypto/fw.h:65:41: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://patch.msgid.link/aSfDqouLFcA4h8JX@kspp Signed-off-by: Kees Cook <kees@kernel.org>
1 parent cd8da63 commit ee4acc5

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

  • drivers/net/ethernet/netronome/nfp/crypto

drivers/net/ethernet/netronome/nfp/crypto/fw.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@ struct nfp_crypto_req_reset {
3232
#define NFP_NET_TLS_VLAN_UNUSED 4095
3333

3434
struct nfp_crypto_req_add_front {
35-
struct nfp_ccm_hdr hdr;
36-
__be32 ep_id;
37-
u8 resv[3];
38-
u8 opcode;
39-
u8 key_len;
40-
__be16 ipver_vlan __packed;
41-
u8 l4_proto;
35+
/* New members MUST be added within the struct_group() macro below. */
36+
struct_group_tagged(nfp_crypto_req_add_front_hdr, __hdr,
37+
struct nfp_ccm_hdr hdr;
38+
__be32 ep_id;
39+
u8 resv[3];
40+
u8 opcode;
41+
u8 key_len;
42+
__be16 ipver_vlan __packed;
43+
u8 l4_proto;
44+
);
4245
#define NFP_NET_TLS_NON_ADDR_KEY_LEN 8
4346
u8 l3_addrs[];
4447
};
48+
static_assert(offsetof(struct nfp_crypto_req_add_front, l3_addrs) ==
49+
sizeof(struct nfp_crypto_req_add_front_hdr),
50+
"struct member likely outside of struct_group_tagged()");
4551

4652
struct nfp_crypto_req_add_back {
4753
__be16 src_port;
@@ -55,14 +61,14 @@ struct nfp_crypto_req_add_back {
5561
};
5662

5763
struct nfp_crypto_req_add_v4 {
58-
struct nfp_crypto_req_add_front front;
64+
struct nfp_crypto_req_add_front_hdr front;
5965
__be32 src_ip;
6066
__be32 dst_ip;
6167
struct nfp_crypto_req_add_back back;
6268
};
6369

6470
struct nfp_crypto_req_add_v6 {
65-
struct nfp_crypto_req_add_front front;
71+
struct nfp_crypto_req_add_front_hdr front;
6672
__be32 src_ip[4];
6773
__be32 dst_ip[4];
6874
struct nfp_crypto_req_add_back back;

drivers/net/ethernet/netronome/nfp/crypto/tls.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ nfp_net_tls_set_ipv4(struct nfp_net *nn, struct nfp_crypto_req_add_v4 *req,
180180
req->front.key_len += sizeof(__be32) * 2;
181181

182182
if (direction == TLS_OFFLOAD_CTX_DIR_TX) {
183-
nfp_net_tls_assign_conn_id(nn, &req->front);
183+
nfp_net_tls_assign_conn_id(nn,
184+
container_of(&req->front,
185+
struct nfp_crypto_req_add_front, __hdr));
184186
} else {
185187
req->src_ip = inet->inet_daddr;
186188
req->dst_ip = inet->inet_saddr;
@@ -199,7 +201,9 @@ nfp_net_tls_set_ipv6(struct nfp_net *nn, struct nfp_crypto_req_add_v6 *req,
199201
req->front.key_len += sizeof(struct in6_addr) * 2;
200202

201203
if (direction == TLS_OFFLOAD_CTX_DIR_TX) {
202-
nfp_net_tls_assign_conn_id(nn, &req->front);
204+
nfp_net_tls_assign_conn_id(nn,
205+
container_of(&req->front,
206+
struct nfp_crypto_req_add_front, __hdr));
203207
} else {
204208
memcpy(req->src_ip, &sk->sk_v6_daddr, sizeof(req->src_ip));
205209
memcpy(req->dst_ip, &np->saddr, sizeof(req->dst_ip));

0 commit comments

Comments
 (0)