Skip to content

Commit 0a3e693

Browse files
GustavoARSilvakuba-moo
authored andcommitted
net/smc: Use static_assert() to check struct sizes
Commit 9748dbc ("net/smc: Avoid -Wflex-array-member-not-at-end warnings") introduced tagged `struct smc_clc_v2_extension_fixed` and `struct smc_clc_smcd_v2_extension_fixed`. We want to ensure that when new members need to be added to the flexible structures, they are always included within these tagged structs. So, we use `static_assert()` to ensure that the memory layout for both the flexible structure and the tagged struct is the same after any changes. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Jan Karcher <jaka@linux.ibm.com> Link: https://patch.msgid.link/ZrVBuiqFHAORpFxE@cute Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 46dd90f commit 0a3e693

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/smc/smc_clc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ struct smc_clc_v2_extension {
145145
);
146146
u8 user_eids[][SMC_MAX_EID_LEN];
147147
};
148+
static_assert(offsetof(struct smc_clc_v2_extension, user_eids) == sizeof(struct smc_clc_v2_extension_fixed),
149+
"struct member likely outside of struct_group_tagged()");
148150

149151
struct smc_clc_msg_proposal_prefix { /* prefix part of clc proposal message*/
150152
__be32 outgoing_subnet; /* subnet mask */
@@ -169,6 +171,8 @@ struct smc_clc_smcd_v2_extension {
169171
);
170172
struct smc_clc_smcd_gid_chid gidchid[];
171173
};
174+
static_assert(offsetof(struct smc_clc_smcd_v2_extension, gidchid) == sizeof(struct smc_clc_smcd_v2_extension_fixed),
175+
"struct member likely outside of struct_group_tagged()");
172176

173177
struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */
174178
struct smc_clc_msg_hdr hdr;

0 commit comments

Comments
 (0)