net/smc: Avoid -Wflex-array-member-not-at-end warnings
PATCH 1/1 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_hdr, hdr,
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_hdr pclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_hdr 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;
| ^~~~~~~~~~~~~~~~--- net/smc/smc_clc.c | 5 +++-- net/smc/smc_clc.h | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-)
net/smc/smc_clc.c +3 -2
@@ -853,8 +853,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, struct smc_clc_v2_extension, _hdr); + smcd_v2_ext =container_of (&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, hdr); gidchids = pclc->pclc_gidchids; trl = &pclc->pclc_trl;
net/smc/smc_clc.h +14 -10
@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {*/ struct smc_clc_v2_extension { -struct smc_clnt_opts_area_hdr hdr; -u8 roce[16 ];/* RoCEv2 GID */ -u8 max_conns; -u8 max_links; -__be16 feature_mask; -u8 reserved[12 ]; + struct_group_tagged(smc_clc_v2_extension_hdr, _hdr, + struct smc_clnt_opts_area_hdr hdr; +u8 roce[16 ];/* RoCEv2 GID */ +u8 max_conns; +u8 max_links; +__be16 feature_mask; +u8 reserved[12 ]; + );u8 user_eids[][SMC_MAX_EID_LEN ]; };
@@ -159,8 +161,10 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */ };struct smc_clc_smcd_v2_extension { -u8 system_eid[SMC_MAX_EID_LEN ]; -u8 reserved[16 ]; + struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr, + u8 system_eid[SMC_MAX_EID_LEN]; +u8 reserved[16 ]; + );struct smc_clc_smcd_gid_chid gidchid[]; };
@@ -183,9 +187,9 @@ struct smc_clc_msg_proposal_area {struct smc_clc_msg_smcd pclc_smcd;struct smc_clc_msg_proposal_prefix pclc_prfx;struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX ]; -struct smc_clc_v2_extension pclc_v2_ext; +struct smc_clc_v2_extension_hdr pclc_v2_ext;u8 user_eids[SMC_CLC_MAX_UEID ][SMC_MAX_EID_LEN ]; -struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; +struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;struct smc_clc_smcd_gid_chid pclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES ];struct smc_clc_msg_trail pclc_trl;
Signature · 1 line
2.34.1
Quoted 46 lines · Gustavo A. R. Silva
-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_areathat 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_hdr, hdr, 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_hdr pclc_v2_ext; ... struct smc_clc_smcd_v2_extension_hdr 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]
Quoted 7 lines
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; | ^~~~~~~~~~~~~~~~Signed-off-by Gustavo A. R. Silva <[email protected]>
I think this is a nice way to deal with these flex-array cases. Using the struct_group() and container_of() means there is very little collateral impact. Since this is isolated to a single file, I wonder if it's easy to check that there are no binary differences too? I wouldn't expect any -- container_of() is all constant expressions, so the assignment offsets should all be the same, etc.
-Kees
Signature · 1 line
Kees Cook
Wen Gu
reviewerQuoted 114 lines · Gustavo A. R. Silva
-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_areathat 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_hdr, hdr, 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_hdr pclc_v2_ext; ... struct smc_clc_smcd_v2_extension_hdr 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; | ^~~~~~~~~~~~~~~~Signed-off-by Gustavo A. R. Silva <[email protected]>--- net/smc/smc_clc.c | 5 +++-- net/smc/smc_clc.h | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-)net/smc/smc_clc.c +3
-2@@ -853,8 +853,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, struct smc_clc_v2_extension, _hdr); + smcd_v2_ext =container_of (&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, hdr); gidchids = pclc->pclc_gidchids; trl = &pclc->pclc_trl;net/smc/smc_clc.h +12
-8@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {*/ struct smc_clc_v2_extension { -struct smc_clnt_opts_area_hdr hdr; -u8 roce[16 ];/* RoCEv2 GID */ -u8 max_conns; -u8 max_links; -__be16 feature_mask; -u8 reserved[12 ]; + struct_group_tagged(smc_clc_v2_extension_hdr, _hdr, + struct smc_clnt_opts_area_hdr hdr; +u8 roce[16 ];/* RoCEv2 GID */ +u8 max_conns; +u8 max_links; +__be16 feature_mask; +u8 reserved[12 ]; + );u8 user_eids[][SMC_MAX_EID_LEN ]; };@@ -159,8 +161,10 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */ };struct smc_clc_smcd_v2_extension { -u8 system_eid[SMC_MAX_EID_LEN ]; -u8 reserved[16 ]; + struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr, + u8 system_eid[SMC_MAX_EID_LEN]; +u8 reserved[16 ]; + );struct smc_clc_smcd_gid_chid gidchid[]; };@@ -183,9 +187,9 @@ struct smc_clc_msg_proposal_area {struct smc_clc_msg_smcd pclc_smcd;
net/smc/smc_clc.h struct smc_clc_msg_proposal_area { · line 195
Quoted 10 lines
net/smc/smc_clc.h +2
-2struct smc_clc_msg_proposal_prefix pclc_prfx;struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX ]; -struct smc_clc_v2_extension pclc_v2_ext; +struct smc_clc_v2_extension_hdr pclc_v2_ext;u8 user_eids[SMC_CLC_MAX_UEID ][SMC_MAX_EID_LEN ]; -struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; +struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;struct smc_clc_smcd_gid_chid pclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES ];struct smc_clc_msg_trail pclc_trl;
Thank you! Gustavo. This patch can fix this warning well, just the name '*_hdr' might not be very accurate, but I don't have a good idea ATM.
Besides, I am wondering if this can be fixed by moving user_eids of smc_clc_msg_proposal_area into smc_clc_v2_extension, andpclc_gidchids of smc_clc_msg_proposal_area into smc_clc_smcd_v2_extension.
so that we can avoid to use the flexible-array in smc_clc_v2_extension and smc_clc_smcd_v2_extension.
net/smc/smc_clc.c +1 -1
@@ -855,7 +855,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) ipv6_prfx = pclc->pclc_prfx_ipv6; v2_ext = &pclc->pclc_v2_ext; smcd_v2_ext = &pclc->pclc_smcd_v2_ext; - gidchids = pclc->pclc_gidchids; + gidchids = pclc->pclc_smcd_v2_ext.gidchid; trl = &pclc->pclc_trl; pclc_base->hdr.version =SMC_V2 ;
net/smc/smc_clc.h +10 -13
@@ -133,6 +133,14 @@ struct smc_clc_smcd_gid_chid {* (https://www.ibm.com/support/pages/node/6326337) */ +#define SMC_CLC_MAX_V6_PREFIX 8 +#define SMC_CLC_MAX_UEID 8 +#define SMCD_CLC_MAX_V2_GID_ENTRIES 8/* max # of CHID-GID entries in CLC +* proposal SMC-Dv2 extension. +* each ISM device takes one entry and +* each Emulated-ISM takes two entries +*/ +struct smc_clc_v2_extension {struct smc_clnt_opts_area_hdr hdr;u8 roce[16 ];/* RoCEv2 GID */
@@ -140,7 +148,7 @@ struct smc_clc_v2_extension {u8 max_links;__be16 feature_mask;u8 reserved[12 ]; -u8 user_eids[][SMC_MAX_EID_LEN ]; +u8 user_eids[SMC_CLC_MAX_UEID ][SMC_MAX_EID_LEN ]; };struct smc_clc_msg_proposal_prefix {/* prefix part of clc proposal message*/
@@ -161,7 +169,7 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */struct smc_clc_smcd_v2_extension {u8 system_eid[SMC_MAX_EID_LEN ];u8 reserved[16 ]; -struct smc_clc_smcd_gid_chid gidchid[]; +struct smc_clc_smcd_gid_chid gidchid[SMCD_CLC_MAX_V2_GID_ENTRIES ]; };struct smc_clc_msg_proposal {/* clc proposal message sent by Linux */
@@ -170,24 +178,13 @@ struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */__be16 iparea_offset;/* offset to IP address information area */ }__aligned(4) ; -#define SMC_CLC_MAX_V6_PREFIX 8 -#define SMC_CLC_MAX_UEID 8 -#define SMCD_CLC_MAX_V2_GID_ENTRIES 8/* max # of CHID-GID entries in CLC -* proposal SMC-Dv2 extension. -* each ISM device takes one entry and -* each Emulated-ISM takes two entries -*/ -struct smc_clc_msg_proposal_area {struct smc_clc_msg_proposal pclc_base;struct smc_clc_msg_smcd pclc_smcd;struct smc_clc_msg_proposal_prefix pclc_prfx;struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX ];struct smc_clc_v2_extension pclc_v2_ext; -u8 user_eids[SMC_CLC_MAX_UEID ][SMC_MAX_EID_LEN ];struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; -struct smc_clc_smcd_gid_chid - pclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES ];struct smc_clc_msg_trail pclc_trl; };
Thanks!
Wen Gu
Quoted 9 lines · Wen Gu
Quoted 6 lines · Gustavo A. R. Silva
-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_areathat contain a couple of flexible structures:
Thank you Gustavo for the proposal.
I had to do some reading to better understand what's happening and how your patch solves this.
Quoted 111 lines
Quoted 111 lines
struct
smc_clc_msg_proposal_area{
...
struct smc_clc_v2_extensionpclc_v2_ext;
...
struct smc_clc_smcd_v2_extensionpclc_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_hdr, hdr, u8 system_eid[SMC_MAX_EID_LEN]; u8 reserved[16];
);
structsmc_clc_smcd_gid_chidgidchid[];
};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_hdrpclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_hdrpclc_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_extensionpclc_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 | structsmc_clc_smcd_v2_extensionpclc_smcd_v2_ext;
| ^~~~~~~~~~~~~~~~Signed-off-by Gustavo A. R. Silva <[email protected]>---
net/smc/smc_clc.c| 5 +++--
net/smc/smc_clc.h| 24 ++++++++++++++----------2 files changed, 17 insertions(+), 12 deletions(-)net/smc/smc_clc.c +3
-2@@ -853,8 +853,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, struct smc_clc_v2_extension, _hdr); + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, hdr); gidchids = pclc->pclc_gidchids;trl =
&pclc->pclc_trl;net/smc/smc_clc.h +8
-6@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {*/ struct smc_clc_v2_extension { - struct smc_clnt_opts_area_hdr hdr; - u8 roce[16]; /* RoCEv2 GID */ - u8 max_conns; - u8 max_links; - __be16 feature_mask; - u8 reserved[12]; + struct_group_tagged(smc_clc_v2_extension_hdr, _hdr, + struct smc_clnt_opts_area_hdr hdr; + u8 roce[16]; /* RoCEv2 GID */ + u8 max_conns; + u8 max_links; + __be16 feature_mask; + u8 reserved[12]; + ); u8 user_eids[][SMC_MAX_EID_LEN]; };@@ -159,8 +161,10 @@ struct smc_clc_msg_smcd { /* SMC-D GIDinformation */
};
structsmc_clc_smcd_v2_extension{
- u8 system_eid[SMC_MAX_EID_LEN];
- u8 reserved[16];
+ struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr, + u8 system_eid[SMC_MAX_EID_LEN];
+ u8 reserved[16];
+ );
structsmc_clc_smcd_gid_chidgidchid[];
};net/smc/smc_clc.h +1
-1@@ -183,9 +187,9 @@ struct smc_clc_msg_proposal_area { struct smc_clc_msg_smcd pclc_smcd; struct smc_clc_msg_proposal_prefix pclc_prfx; struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX]; - struct smc_clc_v2_extension pclc_v2_ext; + struct smc_clc_v2_extension_hdr pclc_v2_ext; u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];
Quoted 8 lines
Quoted 5 lines
net/smc/smc_clc.h +1
-1- struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; + struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;struct
smc_clc_smcd_gid_chidpclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES]; struct smc_clc_msg_trailpclc_trl;Thank you! Gustavo. This patch can fix this warning well, just the name '
*_hdr' might not be very accurate, but I don't have a good idea ATM.
I agree. Should we chose this option we should come up for a better name.
Quoted 8 lines
Besides, I am wondering if this can be fixed by moving
user_eidsofsmc_clc_msg_proposal_areaintosmc_clc_v2_extension, andpclc_gidchidsofsmc_clc_msg_proposal_areaintosmc_clc_smcd_v2_extension.so that we can avoid to use the flexible-array in
smc_clc_v2_extensionandsmc_clc_smcd_v2_extension.
I like the idea and put some thought into it. The only thing that is not perfectly clean IMO is the following:
By the current definition it is easily visible that we are dealing with a variable sized array. If we move them into the structs one could think they are always at their MAX size which they are not. E.g.: An incoming proposal can have 0 UEIDs indicated by the eid_cnt.
That said nothing a comment can't fix.
From what i have seen the offset and length calculations regarding the "real" size of those structs is fine with your proposal.
Can you verify that your changes also resolve the warnings?
[...]
Quoted 5 lines
};
Thanks!
Wen Gu
Thanks you
- Jan
Gustavo A. R. Silva
Reviewed-byQuoted 144 lines · Jan Karcher
Quoted 9 lines · Wen Gu
Quoted 6 lines · Gustavo A. R. Silva
-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_areathat contain a couple of flexible structures:Thank you Gustavo for the proposal.
I had to do some reading to better understand what's happening and how your patch solves this.Quoted 108 lines
Quoted 108 lines
struct
smc_clc_msg_proposal_area{
...
struct smc_clc_v2_extensionpclc_v2_ext;
...
struct smc_clc_smcd_v2_extensionpclc_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_hdr, hdr, u8 system_eid[SMC_MAX_EID_LEN]; u8 reserved[16];
);
structsmc_clc_smcd_gid_chidgidchid[];
};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_hdrpclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_hdrpclc_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_extensionpclc_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 | structsmc_clc_smcd_v2_extensionpclc_smcd_v2_ext;
| ^~~~~~~~~~~~~~~~Signed-off-by Gustavo A. R. Silva <[email protected]>---
net/smc/smc_clc.c| 5 +++--
net/smc/smc_clc.h| 24 ++++++++++++++----------2 files changed, 17 insertions(+), 12 deletions(-)net/smc/smc_clc.c +3
-2@@ -853,8 +853,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, struct smc_clc_v2_extension, _hdr); + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, hdr); gidchids = pclc->pclc_gidchids; trl = &pclc->pclc_trl;net/smc/smc_clc.h +13
-9@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {*/ struct smc_clc_v2_extension { - struct smc_clnt_opts_area_hdr hdr; - u8 roce[16]; /* RoCEv2 GID */ - u8 max_conns; - u8 max_links; - __be16 feature_mask; - u8 reserved[12]; + struct_group_tagged(smc_clc_v2_extension_hdr, _hdr, + struct smc_clnt_opts_area_hdr hdr; + u8 roce[16]; /* RoCEv2 GID */ + u8 max_conns; + u8 max_links; + __be16 feature_mask; + u8 reserved[12]; + ); u8 user_eids[][SMC_MAX_EID_LEN]; };@@ -159,8 +161,10 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */ }; struct smc_clc_smcd_v2_extension { - u8 system_eid[SMC_MAX_EID_LEN]; - u8 reserved[16]; + struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr, + u8 system_eid[SMC_MAX_EID_LEN]; + u8 reserved[16]; + ); struct smc_clc_smcd_gid_chid gidchid[]; };@@ -183,9 +187,9 @@ struct smc_clc_msg_proposal_area { struct smc_clc_msg_smcd pclc_smcd; struct smc_clc_msg_proposal_prefix pclc_prfx; struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX]; - struct smc_clc_v2_extension pclc_v2_ext; + struct smc_clc_v2_extension_hdr pclc_v2_ext; u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];Quoted 8 lines
Quoted 5 lines
net/smc/smc_clc.h +1
-1- struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; + struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;struct
smc_clc_smcd_gid_chidpclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES]; struct smc_clc_msg_trailpclc_trl;Thank you! Gustavo. This patch can fix this warning well, just the name '
*_hdr' might not be very accurate, but I don't have a good idea ATM.I agree. Should we chose this option we should come up for a better name.
Quoted 8 lines
Besides, I am wondering if this can be fixed by moving
user_eidsofsmc_clc_msg_proposal_areaintosmc_clc_v2_extension, andpclc_gidchidsofsmc_clc_msg_proposal_areaintosmc_clc_smcd_v2_extension.so that we can avoid to use the flexible-array in
smc_clc_v2_extensionandsmc_clc_smcd_v2_extension.
Quoted 8 lines
I like the idea and put some thought into it. The only thing that is not perfectly clean IMO is the following:
By the current definition it is easily visible that we are dealing with a variable sized array. If we move them into the structs one could think they are always at their MAX size which they are not. E.g.: An incoming proposal can have 0 UEIDs indicated by theeid_cnt.
That said nothing a comment can't fix.From what i have seen the offset and length calculations regarding the "real" size of those structs is fine with your proposal.
Can you verify that your changes also resolve the warnings?
I can confirm that the changes Wen Gu is proposing also resolve the warnings.
Wen,
If you send a proper patch, you can include the following tags:
Thanks!
--
Gustavo
Quoted 11 lines
[...]
Quoted 5 lines
};
Thanks!
Wen GuThanks you
- Jan
Wen Gu
reviewerQuoted 156 lines · Gustavo A. R. Silva
Quoted 144 lines · Jan Karcher
Quoted 9 lines · Wen Gu
Quoted 6 lines · Gustavo A. R. Silva
-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_areathat contain a couple of flexible structures:Thank you Gustavo for the proposal.
I had to do some reading to better understand what's happening and how your patch solves this.Quoted 108 lines
Quoted 108 lines
struct
smc_clc_msg_proposal_area{
...
struct smc_clc_v2_extensionpclc_v2_ext;
...
struct smc_clc_smcd_v2_extensionpclc_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_hdr, hdr, u8 system_eid[SMC_MAX_EID_LEN]; u8 reserved[16];
);
structsmc_clc_smcd_gid_chidgidchid[];
};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_hdrpclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_hdrpclc_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_extensionpclc_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 | structsmc_clc_smcd_v2_extensionpclc_smcd_v2_ext;
| ^~~~~~~~~~~~~~~~Signed-off-by Gustavo A. R. Silva <[email protected]>---
net/smc/smc_clc.c| 5 +++--
net/smc/smc_clc.h| 24 ++++++++++++++----------2 files changed, 17 insertions(+), 12 deletions(-)net/smc/smc_clc.c +3
-2@@ -853,8 +853,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, struct smc_clc_v2_extension, _hdr); + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, hdr); gidchids = pclc->pclc_gidchids; trl = &pclc->pclc_trl;net/smc/smc_clc.h +13
-9@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {*/ struct smc_clc_v2_extension { - struct smc_clnt_opts_area_hdr hdr; - u8 roce[16]; /* RoCEv2 GID */ - u8 max_conns; - u8 max_links; - __be16 feature_mask; - u8 reserved[12]; + struct_group_tagged(smc_clc_v2_extension_hdr, _hdr, + struct smc_clnt_opts_area_hdr hdr; + u8 roce[16]; /* RoCEv2 GID */ + u8 max_conns; + u8 max_links; + __be16 feature_mask; + u8 reserved[12]; + ); u8 user_eids[][SMC_MAX_EID_LEN]; };@@ -159,8 +161,10 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */ }; struct smc_clc_smcd_v2_extension { - u8 system_eid[SMC_MAX_EID_LEN]; - u8 reserved[16]; + struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr, + u8 system_eid[SMC_MAX_EID_LEN]; + u8 reserved[16]; + ); struct smc_clc_smcd_gid_chid gidchid[]; };@@ -183,9 +187,9 @@ struct smc_clc_msg_proposal_area { struct smc_clc_msg_smcd pclc_smcd; struct smc_clc_msg_proposal_prefix pclc_prfx; struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX]; - struct smc_clc_v2_extension pclc_v2_ext; + struct smc_clc_v2_extension_hdr pclc_v2_ext; u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];Quoted 8 lines
Quoted 5 lines
net/smc/smc_clc.h +1
-1- struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; + struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;struct
smc_clc_smcd_gid_chidpclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES]; struct smc_clc_msg_trailpclc_trl;Thank you! Gustavo. This patch can fix this warning well, just the name '
*_hdr' might not be very accurate, but I don't have a good idea ATM.I agree. Should we chose this option we should come up for a better name.
Quoted 8 lines
Besides, I am wondering if this can be fixed by moving
user_eidsofsmc_clc_msg_proposal_areaintosmc_clc_v2_extension, andpclc_gidchidsofsmc_clc_msg_proposal_areaintosmc_clc_smcd_v2_extension.so that we can avoid to use the flexible-array in
smc_clc_v2_extensionandsmc_clc_smcd_v2_extension.Quoted 8 lines
I like the idea and put some thought into it. The only thing that is not perfectly clean IMO is the following:
By the current definition it is easily visible that we are dealing with a variable sized array. If we move them into the structs one could think they are always at their MAX size which they are not. E.g.: An incoming proposal can have 0 UEIDs indicated by theeid_cnt.
That said nothing a comment can't fix.From what i have seen the offset and length calculations regarding the "real" size of those structs is fine with your proposal.
Can you verify that your changes also resolve the warnings?
Quoted 9 lines
I can confirm that the changes Wen Gu is proposing also resolve the warnings.
Wen,
If you send a proper patch, you can include the following tags:
Reviewed-by Gustavo A. R. Silva <[email protected]>Build-tested-by Gustavo A. R. Silva <[email protected]>
Hi Gustavo, thank you for the confirmation that my proposal can fix the warning.
But I found that I may have something missed in my proposal when I think further. My proposal changed the sizes of struct smc_clc_v2_extension and smc_clc_smcd_v2_extension, and some places in SMC need them, such as the fill of kvec in smc_clc_send_proposal().
So my proposal may involve more changes to current SMC code, and I think it is not as clean as your solution. So I perfer yours now.
And as for the name, I think maybe we can use '*_elems' as a suffix, at least it is unambiguous. So it will be smc_clc_v2_extension_elems and smc_clc_smcd_v2_extension_elems.
Jan, what do you think of the name '*_elems' ?
Thanks!
Quoted 15 lines
Thanks!
Signature · 1 line
GustavoQuoted 11 lines
[...]
Quoted 5 lines
};
Thanks!
Wen GuThanks you
- Jan
Quoted 172 lines · Wen Gu
Quoted 159 lines · Gustavo A. R. Silva
Quoted 147 lines · Jan Karcher
Quoted 9 lines · Wen Gu
Quoted 6 lines · Gustavo A. R. Silva
-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_areathat contain a couple of flexible structures:Thank you Gustavo for the proposal.
I had to do some reading to better understand what's happening and how your patch solves this.Quoted 111 lines
Quoted 111 lines
struct
smc_clc_msg_proposal_area{
...
struct smc_clc_v2_extensionpclc_v2_ext;
...
struct smc_clc_smcd_v2_extensionpclc_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_hdr, hdr, u8 system_eid[SMC_MAX_EID_LEN]; u8 reserved[16];
);
structsmc_clc_smcd_gid_chidgidchid[];
};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_hdrpclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_hdrpclc_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_extensionpclc_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 | structsmc_clc_smcd_v2_extensionpclc_smcd_v2_ext;
| ^~~~~~~~~~~~~~~~Signed-off-by Gustavo A. R. Silva <[email protected]>---
net/smc/smc_clc.c| 5 +++--
net/smc/smc_clc.h| 24 ++++++++++++++----------2 files changed, 17 insertions(+), 12 deletions(-)net/smc/smc_clc.c +3
-2@@ -853,8 +853,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, struct smc_clc_v2_extension, _hdr); + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, hdr); gidchids = pclc->pclc_gidchids;trl =
&pclc->pclc_trl;net/smc/smc_clc.h +8
-6@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {*/ struct smc_clc_v2_extension { - struct smc_clnt_opts_area_hdr hdr; - u8 roce[16]; /* RoCEv2 GID */ - u8 max_conns; - u8 max_links; - __be16 feature_mask; - u8 reserved[12]; + struct_group_tagged(smc_clc_v2_extension_hdr, _hdr, + struct smc_clnt_opts_area_hdr hdr; + u8 roce[16]; /* RoCEv2 GID */ + u8 max_conns; + u8 max_links; + __be16 feature_mask; + u8 reserved[12]; + ); u8 user_eids[][SMC_MAX_EID_LEN]; };@@ -159,8 +161,10 @@ struct smc_clc_msg_smcd { /* SMC-D GIDinformation */
};
structsmc_clc_smcd_v2_extension{
- u8 system_eid[SMC_MAX_EID_LEN];
- u8 reserved[16];
+ struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr, + u8 system_eid[SMC_MAX_EID_LEN];
+ u8 reserved[16];
+ );
structsmc_clc_smcd_gid_chidgidchid[];
};net/smc/smc_clc.h +1
-1@@ -183,9 +187,9 @@ struct smc_clc_msg_proposal_area { struct smc_clc_msg_smcd pclc_smcd; struct smc_clc_msg_proposal_prefix pclc_prfx; struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX]; - struct smc_clc_v2_extension pclc_v2_ext; + struct smc_clc_v2_extension_hdr pclc_v2_ext; u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];Quoted 8 lines
Quoted 5 lines
net/smc/smc_clc.h +1
-1- struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; + struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;struct
smc_clc_smcd_gid_chidpclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES]; struct smc_clc_msg_trailpclc_trl;Thank you! Gustavo. This patch can fix this warning well, just the name '
*_hdr' might not be very accurate, but I don't have a good idea ATM.I agree. Should we chose this option we should come up for a better name.
Quoted 8 lines
Besides, I am wondering if this can be fixed by moving
user_eidsofsmc_clc_msg_proposal_areaintosmc_clc_v2_extension, andpclc_gidchidsofsmc_clc_msg_proposal_areaintosmc_clc_smcd_v2_extension.so that we can avoid to use the flexible-array in
smc_clc_v2_extensionandsmc_clc_smcd_v2_extension.Quoted 8 lines
I like the idea and put some thought into it. The only thing that is not perfectly clean IMO is the following:
By the current definition it is easily visible that we are dealing with a variable sized array. If we move them into the structs one could think they are always at their MAX size which they are not. E.g.: An incoming proposal can have 0 UEIDs indicated by theeid_cnt.
That said nothing a comment can't fix.From what i have seen the offset and length calculations regarding the "real" size of those structs is fine with your proposal.
Can you verify that your changes also resolve the warnings?
Quoted 9 lines
I can confirm that the changes Wen Gu is proposing also resolve the warnings.
Wen,
If you send a proper patch, you can include the following tags:
Reviewed-by Gustavo A. R. Silva <[email protected]>Build-tested-by Gustavo A. R. Silva <[email protected]>
Quoted 8 lines
Hi Gustavo, thank you for the confirmation that my proposal can fix the warning.
But I found that I may have something missed in my proposal when I think further. My proposal changed the sizes of struct
smc_clc_v2_extensionandsmc_clc_smcd_v2_extension, and some places in SMC need them, such as the fill of kvec insmc_clc_send_proposal().So my proposal may involve more changes to current SMC code, and I think it is not as clean as your solution. So I perfer yours now.
Hi Wen Gu,
you're right. I missed that the offset calculation is broken with your proposal since the full size of the array is already included in this case which means we would have to subtract the empty slots instead of adding the full ones. My bad. Thinking about adding a testcase to sxplicit check the size of the CLC Messages send in the future.
Quoted 6 lines
And as for the name, I think maybe we can use '
*_elems' as a suffix, at least it is unambiguous. So it will besmc_clc_v2_extension_elemsandsmc_clc_smcd_v2_extension_elems.Jan, what do you think of the name '
*_elems' ?
Hmm... I think it is way better than priv. One more proposal from my side would be *_fixed since this is the fixed content and not variable. I'm open for both.
Which one would you prefer more?
Quoted 18 lines
Thanks!
Quoted 15 lines
Thanks!
Signature · 1 line
GustavoQuoted 11 lines
[...]
Quoted 5 lines
};
Thanks!
Wen GuThanks you
- Jan
Wen Gu
reviewerQuoted 178 lines · Jan Karcher
Quoted 175 lines · Wen Gu
Quoted 156 lines · Gustavo A. R. Silva
Quoted 144 lines · Jan Karcher
Quoted 9 lines · Wen Gu
Quoted 6 lines · Gustavo A. R. Silva
-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_areathat contain a couple of flexible structures:Thank you Gustavo for the proposal.
I had to do some reading to better understand what's happening and how your patch solves this.Quoted 108 lines
Quoted 108 lines
struct
smc_clc_msg_proposal_area{
...
struct smc_clc_v2_extensionpclc_v2_ext;
...
struct smc_clc_smcd_v2_extensionpclc_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_hdr, hdr, u8 system_eid[SMC_MAX_EID_LEN]; u8 reserved[16];
);
structsmc_clc_smcd_gid_chidgidchid[];
};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_hdrpclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_hdrpclc_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_extensionpclc_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 | structsmc_clc_smcd_v2_extensionpclc_smcd_v2_ext;
| ^~~~~~~~~~~~~~~~Signed-off-by Gustavo A. R. Silva <[email protected]>---
net/smc/smc_clc.c| 5 +++--
net/smc/smc_clc.h| 24 ++++++++++++++----------2 files changed, 17 insertions(+), 12 deletions(-)net/smc/smc_clc.c +3
-2@@ -853,8 +853,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) pclc_smcd = &pclc->pclc_smcd; pclc_prfx = &pclc->pclc_prfx; ipv6_prfx = pclc->pclc_prfx_ipv6; - v2_ext = &pclc->pclc_v2_ext; - smcd_v2_ext = &pclc->pclc_smcd_v2_ext; + v2_ext = container_of(&pclc->pclc_v2_ext, struct smc_clc_v2_extension, _hdr); + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, + struct smc_clc_smcd_v2_extension, hdr); gidchids = pclc->pclc_gidchids; trl = &pclc->pclc_trl;net/smc/smc_clc.h +13
-9@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {*/ struct smc_clc_v2_extension { - struct smc_clnt_opts_area_hdr hdr; - u8 roce[16]; /* RoCEv2 GID */ - u8 max_conns; - u8 max_links; - __be16 feature_mask; - u8 reserved[12]; + struct_group_tagged(smc_clc_v2_extension_hdr, _hdr, + struct smc_clnt_opts_area_hdr hdr; + u8 roce[16]; /* RoCEv2 GID */ + u8 max_conns; + u8 max_links; + __be16 feature_mask; + u8 reserved[12]; + ); u8 user_eids[][SMC_MAX_EID_LEN]; };@@ -159,8 +161,10 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */ }; struct smc_clc_smcd_v2_extension { - u8 system_eid[SMC_MAX_EID_LEN]; - u8 reserved[16]; + struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr, + u8 system_eid[SMC_MAX_EID_LEN]; + u8 reserved[16]; + ); struct smc_clc_smcd_gid_chid gidchid[]; };@@ -183,9 +187,9 @@ struct smc_clc_msg_proposal_area { struct smc_clc_msg_smcd pclc_smcd; struct smc_clc_msg_proposal_prefix pclc_prfx; struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX]; - struct smc_clc_v2_extension pclc_v2_ext; + struct smc_clc_v2_extension_hdr pclc_v2_ext; u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];Quoted 8 lines
Quoted 5 lines
net/smc/smc_clc.h +1
-1- struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext; + struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;struct
smc_clc_smcd_gid_chidpclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES]; struct smc_clc_msg_trailpclc_trl;Thank you! Gustavo. This patch can fix this warning well, just the name '
*_hdr' might not be very accurate, but I don't have a good idea ATM.I agree. Should we chose this option we should come up for a better name.
Quoted 8 lines
Besides, I am wondering if this can be fixed by moving
user_eidsofsmc_clc_msg_proposal_areaintosmc_clc_v2_extension, andpclc_gidchidsofsmc_clc_msg_proposal_areaintosmc_clc_smcd_v2_extension.so that we can avoid to use the flexible-array in
smc_clc_v2_extensionandsmc_clc_smcd_v2_extension.Quoted 8 lines
I like the idea and put some thought into it. The only thing that is not perfectly clean IMO is the following:
By the current definition it is easily visible that we are dealing with a variable sized array. If we move them into the structs one could think they are always at their MAX size which they are not. E.g.: An incoming proposal can have 0 UEIDs indicated by theeid_cnt.
That said nothing a comment can't fix.From what i have seen the offset and length calculations regarding the "real" size of those structs is fine with your proposal.
Can you verify that your changes also resolve the warnings?
Quoted 9 lines
I can confirm that the changes Wen Gu is proposing also resolve the warnings.
Wen,
If you send a proper patch, you can include the following tags:
Reviewed-by Gustavo A. R. Silva <[email protected]>Build-tested-by Gustavo A. R. Silva <[email protected]>Hi Gustavo, thank you for the confirmation that my proposal can fix the warning.
But I found that I may have something missed in my proposal when I think further. My proposal changed the sizes of struct
smc_clc_v2_extensionandsmc_clc_smcd_v2_extension, and some places in SMC need them, such as the fill of kvec insmc_clc_send_proposal().
Quoted 8 lines
Quoted 2 lines
So my proposal may involve more changes to current SMC code, and I think it is not as clean as your solution. So I perfer yours now.
Hi Wen Gu,
you're right. I missed that the offset calculation is broken with your proposal since the full size of the array is already included in this case which means we would have to subtract the empty slots instead of adding the full ones. My bad. Thinking about adding a testcase to sxplicit check the size of the CLC Messages send in the future.
That's OK. I am the one who brings this mistake. Sometimes the details only become clear when start writing the code.
Quoted 11 lines
Quoted 6 lines
And as for the name, I think maybe we can use '
*_elems' as a suffix, at least it is unambiguous. So it will besmc_clc_v2_extension_elemsandsmc_clc_smcd_v2_extension_elems.Jan, what do you think of the name '
*_elems' ?Hmm... I think it is way better than priv. One more proposal from my side would be
*_fixedsince this is the fixed content and not variable. I'm open for both.Which one would you prefer more?
'*_fixed' is better, thank you!
Hi Gustavo,
Sorry to complicate things. Could you please post a v2 with the new name updated (avoid using 'hdr') ?
Thank you!
Quoted 18 lines
Quoted 18 lines
Thanks!
Quoted 15 lines
Thanks!
Signature · 1 line
GustavoQuoted 11 lines
[...]
Quoted 5 lines
};
Thanks!
Wen GuThanks you
- Jan