Skip to contentSkip to conversation

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

PATCH In review Gustavo A. R. Silva 4 participants 4 messages Mar 12, 2024 – Mar 25, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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_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;
      |                                                 ^~~~~~~~~~~~~~~~

---
Changes in v2:
- Name the tagged struct *_fixed instead of *_hdr.
- Add Kees' RB tag.

 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
index e55026c7529c..63bb5745ab54 100644
@@ -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, fixed);
+	smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext,
+				   struct smc_clc_smcd_v2_extension, fixed);
 	gidchids = pclc->pclc_gidchids;
 	trl = &pclc->pclc_trl;
 
net/smc/smc_clc.h +14 -10
index 7cc7070b9772..2bfb51daf468 100644
@@ -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_fixed, fixed,
+		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_fixed, fixed,
+		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_fixed	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_fixed	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
maintainer
#1 lore raw
Quoted 2 lines · On Tue, 12 Mar 2024 11:55:19 -0600 Gustavo A. R. Silva wrote:

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

## Form letter - net-next-closed

The merge window for v6.9 has begun and we have already posted our pull request. Therefore net-next is closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.

Please repost when net-next reopens after March 25th.

RFC patches sent for review only are obviously welcome at any time.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle

Signature · 1 line
pw-bot: defer
reviewer
#2 lore raw
In reply to Gustavo A. R. Silva
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_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]

Quoted 8 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;
       |                                                 ^~~~~~~~~~~~~~~~

Hi Gustavo,

Thank you for the v2. Some places may need improvement, see below.

Quoted 14 lines

---
Changes in v2:
- Name the tagged struct *_fixed instead of *_hdr.
- Add Kees' RB tag.

  net/smc/smc_clc.c |  5 +++--
  net/smc/smc_clc.h | 24 ++++++++++++++----------
  2 files changed, 17 insertions(+), 12 deletions(-)
net/smc/smc_clc.c +0 -0
index e55026c7529c..63bb5745ab54 100644

net/smc/smc_clc.c int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) · line 856

Quoted 6 lines
net/smc/smc_clc.c +1 -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, fixed);

checkpatch complained 'WARNING: line length of 86 exceeds 80 columns' here.

It can be reproduced by:

./scripts/checkpatch.pl --strict --max-line-length=80 --ignore=COMMIT_LOG_LONG_LINE,MACRO_ARG_REUSE,ALLOC_SIZEOF_STRUCT,NO_AUTHOR_SIGN_OFF,GIT_COMMIT_ID,CAMELCASE xxx.patch

Quoted 11 lines
net/smc/smc_clc.c +2 -0
+	smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext,
+				   struct smc_clc_smcd_v2_extension, fixed);
  	gidchids = pclc->pclc_gidchids;
  	trl = &pclc->pclc_trl;
 
net/smc/smc_clc.h +0 -0
index 7cc7070b9772..2bfb51daf468 100644
@@ -134,12 +134,14 @@ struct smc_clc_smcd_gid_chid {
  			 */

net/smc/smc_clc.h struct smc_clc_smcd_gid_chid { · line 138

Quoted 10 lines
net/smc/smc_clc.h +2 -6
 
  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_fixed, fixed,
+		struct smc_clnt_opts_area_hdr hdr;

checkpatch: 'CHECK: Alignment should match open parenthesis'

Quoted 10 lines
net/smc/smc_clc.h +6 -0
+		u8 roce[16];		/* RoCEv2 GID */
+		u8 max_conns;
+		u8 max_links;
+		__be16 feature_mask;
+		u8 reserved[12];
+	);
  	u8 user_eids[][SMC_MAX_EID_LEN];
  };
 

net/smc/smc_clc.h struct smc_clc_msg_smcd { /* SMC-D GID information */ · line 165

Quoted 7 lines
net/smc/smc_clc.h +2 -2
@@ -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_fixed, fixed,
+		u8 system_eid[SMC_MAX_EID_LEN];

checkpatch: 'CHECK: Alignment should match open parenthesis'

Thanks!
Wen Gu

Quoted 17 lines
net/smc/smc_clc.h +4 -2
+		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_fixed	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_fixed	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;
#3 lore raw
Quoted 13 lines

net/smc/smc_clc.c int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) · line 856

Quoted 12 lines
net/smc/smc_clc.c +1 -2
index e55026c7529c..63bb5745ab54 100644
@@ -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, fixed);

checkpatch complained 'WARNING: line length of 86 exceeds 80 columns' here.

I could probably change this.

Quoted 19 lines

It can be reproduced by:

./scripts/checkpatch.pl --strict --max-line-length=80 --ignore=COMMIT_LOG_LONG_LINE,MACRO_ARG_REUSE,ALLOC_SIZEOF_STRUCT,NO_AUTHOR_SIGN_OFF,GIT_COMMIT_ID,CAMELCASE xxx.patch

Quoted 13 lines
net/smc/smc_clc.c +2 -0
+    smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext,
+                   struct smc_clc_smcd_v2_extension, fixed);
       gidchids = pclc->pclc_gidchids;
       trl = &pclc->pclc_trl;
net/smc/smc_clc.h +0 -2
index 7cc7070b9772..2bfb51daf468 100644
@@ -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 */
Quoted 8 lines

net/smc/smc_clc.h struct smc_clc_smcd_gid_chid { · line 138

Quoted 6 lines
net/smc/smc_clc.h +2 -4
-    u8 max_conns;
-    u8 max_links;
-    __be16 feature_mask;
-    u8 reserved[12];
+    struct_group_tagged(smc_clc_v2_extension_fixed, fixed,
+        struct smc_clnt_opts_area_hdr hdr;

checkpatch: 'CHECK: Alignment should match open parenthesis'

I think the code looks better as is --without aligning to match the parenthesis.

--
Gustavo