Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/smc: Avoid -Wflex-array-member-not-at-end warnings

-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.

There are currently a couple of objects in `struct smc_clc_msg_proposal_area`
that contain a couple of flexible structures:

struct smc_clc_msg_proposal_area {
...
struct smc_clc_v2_extension pclc_v2_ext;
...
struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
...
};

So, in order to avoid ending up with a couple of flexible-array members
in the middle of a struct, we use the `struct_group_tagged()` helper to
separate the flexible array from the rest of the members in the flexible
structure:

struct smc_clc_smcd_v2_extension {
struct_group_tagged(smc_clc_smcd_v2_extension_fixed, fixed,
u8 system_eid[SMC_MAX_EID_LEN];
u8 reserved[16];
);
struct smc_clc_smcd_gid_chid gidchid[];
};

With the change described above, we now declare objects of the type of
the tagged struct without embedding flexible arrays in the middle of
another struct:

struct smc_clc_msg_proposal_area {
...
struct smc_clc_v2_extension_fixed pclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_fixed pclc_smcd_v2_ext;
...
};

We also use `container_of()` when we need to retrieve a pointer to the
flexible structures.

So, with these changes, fix the following warnings:

In file included from net/smc/af_smc.c:42:
net/smc/smc_clc.h:186:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
186 | struct smc_clc_v2_extension pclc_v2_ext;
| ^~~~~~~~~~~
net/smc/smc_clc.h:188:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
188 | struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
| ^~~~~~~~~~~~~~~~

Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Gustavo A. R. Silva and committed by
David S. Miller
9748dbc9 b1f81b9a

+20 -12
+4 -2
net/smc/smc_clc.c
··· 853 853 pclc_smcd = &pclc->pclc_smcd; 854 854 pclc_prfx = &pclc->pclc_prfx; 855 855 ipv6_prfx = pclc->pclc_prfx_ipv6; 856 - v2_ext = &pclc->pclc_v2_ext; 857 - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; 856 + v2_ext = container_of(&pclc->pclc_v2_ext, 857 + struct smc_clc_v2_extension, fixed); 858 + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, 859 + struct smc_clc_smcd_v2_extension, fixed); 858 860 gidchids = pclc->pclc_gidchids; 859 861 trl = &pclc->pclc_trl; 860 862
+16 -10
net/smc/smc_clc.h
··· 134 134 */ 135 135 136 136 struct smc_clc_v2_extension { 137 - struct smc_clnt_opts_area_hdr hdr; 138 - u8 roce[16]; /* RoCEv2 GID */ 139 - u8 max_conns; 140 - u8 max_links; 141 - __be16 feature_mask; 142 - u8 reserved[12]; 137 + /* New members must be added within the struct_group() macro below. */ 138 + struct_group_tagged(smc_clc_v2_extension_fixed, fixed, 139 + struct smc_clnt_opts_area_hdr hdr; 140 + u8 roce[16]; /* RoCEv2 GID */ 141 + u8 max_conns; 142 + u8 max_links; 143 + __be16 feature_mask; 144 + u8 reserved[12]; 145 + ); 143 146 u8 user_eids[][SMC_MAX_EID_LEN]; 144 147 }; 145 148 ··· 162 159 }; 163 160 164 161 struct smc_clc_smcd_v2_extension { 165 - u8 system_eid[SMC_MAX_EID_LEN]; 166 - u8 reserved[16]; 162 + /* New members must be added within the struct_group() macro below. */ 163 + struct_group_tagged(smc_clc_smcd_v2_extension_fixed, fixed, 164 + u8 system_eid[SMC_MAX_EID_LEN]; 165 + u8 reserved[16]; 166 + ); 167 167 struct smc_clc_smcd_gid_chid gidchid[]; 168 168 }; 169 169 ··· 189 183 struct smc_clc_msg_smcd pclc_smcd; 190 184 struct smc_clc_msg_proposal_prefix pclc_prfx; 191 185 struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX]; 192 - struct smc_clc_v2_extension pclc_v2_ext; 186 + struct smc_clc_v2_extension_fixed pclc_v2_ext; 193 187 u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN]; 194 - struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; 188 + struct smc_clc_smcd_v2_extension_fixed pclc_smcd_v2_ext; 195 189 struct smc_clc_smcd_gid_chid 196 190 pclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES]; 197 191 struct smc_clc_msg_trail pclc_trl;