RDMA/cm: Avoid -Wflex-array-member-not-at-end warning
PATCH 1/1 RDMA/cm: Avoid -Wflex-array-member-not-at-end warning
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally.
Use the struct_group_tagged() helper to separate the flexible array from the rest of the members in flexible struct cm_work, and avoid embedding the flexible-array member in struct cm_timewait_info.
Also, use container_of() to retrieve a pointer to the flexible structure.
So, with these changes, fix the following warning:drivers/infiniband/core/cm.c:196:24: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
--- drivers/infiniband/core/cm.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/infiniband/core/cm.c +12 -9
@@ -182,18 +182,21 @@ struct cm_av { };struct cm_work { -struct delayed_work work; -struct list_head list; -struct cm_port *port; -struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ -__be32 local_id;/* Established / timewait */ -__be32 remote_id; -struct ib_cm_event cm_event; +/* New members must be added within the struct_group() macro below. */ + struct_group_tagged(cm_work_hdr, hdr, + struct delayed_work work; +struct list_head list; +struct cm_port *port; +struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ +__be32 local_id;/* Established / timewait */ +__be32 remote_id; +struct ib_cm_event cm_event; + );struct sa_path_rec path[]; };struct cm_timewait_info { -struct cm_work work; +struct cm_work_hdr work;struct list_head list;struct rb_node remote_qp_node;struct rb_node remote_id_node;
@@ -3440,7 +3443,7 @@ static int cm_timewait_handler(struct cm_work *work)struct cm_timewait_info *timewait_info;struct cm_id_private *cm_id_priv; - timewait_info = container_of(work, struct cm_timewait_info, work); + timewait_info = container_of(&work->hdr, struct cm_timewait_info, work);spin_lock_irq (&cm.lock);list_del (&timewait_info->list);spin_unlock_irq (&cm.lock);
Signature · 1 line
2.34.1
Quoted 35 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.
Use the
struct_group_tagged()helper to separate the flexible array from the rest of the members in flexiblestruct cm_work, and avoid embedding the flexible-array member instruct cm_timewait_info.Also, use
container_of()to retrieve a pointer to the flexible structure.So, with these changes, fix the following warning:
drivers/infiniband/core/cm.c:196:24: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/infiniband/core/cm.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)drivers/infiniband/core/cm.c +2
-7@@ -182,18 +182,21 @@ struct cm_av { };struct cm_work { -struct delayed_work work; -struct list_head list; -struct cm_port *port; -struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ -__be32 local_id;/* Established / timewait */ -__be32 remote_id; -struct ib_cm_event cm_event; +/* New members must be added within the struct_group() macro below. */ + struct_group_tagged(cm_work_hdr, hdr,
drivers/infiniband/core/cm.c struct cm_av { · line 196
Quoted 10 lines
drivers/infiniband/core/cm.c +8
-0+struct delayed_work work; +struct list_head list; +struct cm_port *port; +struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ +__be32 local_id;/* Established / timewait */ +__be32 remote_id; +struct ib_cm_event cm_event; + );struct sa_path_rec path[]; };
I didn't look, but does it make more sense to break out the path side into its own type and avoid the struct_group_tagged? I seem to remember only one thing used it.
Jason
Quoted 42 lines · Jason Gunthorpe
Quoted 41 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.
Use the
struct_group_tagged()helper to separate the flexible array from the rest of the members in flexiblestruct cm_work, and avoid embedding the flexible-array member instruct cm_timewait_info.Also, use
container_of()to retrieve a pointer to the flexible structure.So, with these changes, fix the following warning:
drivers/infiniband/core/cm.c:196:24: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/infiniband/core/cm.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)drivers/infiniband/core/cm.c +8
-7@@ -182,18 +182,21 @@ struct cm_av { };struct cm_work { -struct delayed_work work; -struct list_head list; -struct cm_port *port; -struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ -__be32 local_id;/* Established / timewait */ -__be32 remote_id; -struct ib_cm_event cm_event; +/* New members must be added within the struct_group() macro below. */ + struct_group_tagged(cm_work_hdr, hdr, + struct delayed_work work; +struct list_head list; +struct cm_port *port; +struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ +__be32 local_id;/* Established / timewait */ +__be32 remote_id;
Quoted 9 lines
drivers/infiniband/core/cm.c struct cm_av { · line 196
Quoted 4 lines
drivers/infiniband/core/cm.c +2
-0+struct ib_cm_event cm_event; + );struct sa_path_rec path[]; };I didn't look, but does it make more sense to break out the path side into its own type and avoid the
struct_group_tagged? I seem to remember only one thing used it.
I thought about that, but I'd have to change the parameter type of static int cm_timewait_handler(struct cm_work *work), and that would imply also modifying the internals of function cm_work_handler() (and then I didn't look much into it). So, the struct_group_tagged() strategy is in general more cleaner and straightforward.
--
Gustavo
Quoted 54 lines · Gustavo A. R. Silva
Quoted 41 lines · Jason Gunthorpe
Quoted 40 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.
Use the
struct_group_tagged()helper to separate the flexible array from the rest of the members in flexiblestruct cm_work, and avoid embedding the flexible-array member instruct cm_timewait_info.Also, use
container_of()to retrieve a pointer to the flexible structure.So, with these changes, fix the following warning:
drivers/infiniband/core/cm.c:196:24: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/infiniband/core/cm.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)drivers/infiniband/core/cm.c +8
-7@@ -182,18 +182,21 @@ struct cm_av { };struct cm_work { -struct delayed_work work; -struct list_head list; -struct cm_port *port; -struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ -__be32 local_id;/* Established / timewait */ -__be32 remote_id; -struct ib_cm_event cm_event; +/* New members must be added within the struct_group() macro below. */ + struct_group_tagged(cm_work_hdr, hdr, + struct delayed_work work; +struct list_head list; +struct cm_port *port; +struct ib_mad_recv_wc *mad_recv_wc;/* Received MADs */ +__be32 local_id;/* Established / timewait */ +__be32 remote_id;Quoted 9 lines
drivers/infiniband/core/cm.c struct cm_av { · line 196
Quoted 4 lines
drivers/infiniband/core/cm.c +2
-0+struct ib_cm_event cm_event; + );struct sa_path_rec path[]; };I didn't look, but does it make more sense to break out the path side into its own type and avoid the
struct_group_tagged? I seem to remember only one thing used it.
Quoted 4 lines
I thought about that, but I'd have to change the parameter type of
static int cm_timewait_handler(struct cm_work *work), and that would imply also modifying the internals of functioncm_work_handler()(and then I didn't look much into it).
So let's try to invest in this direction first before we add obfuscation with magic words to the code.
Thanks
Quoted 6 lines
So, the
struct_group_tagged()strategy is in general more cleaner and straightforward.--
Gustavo