public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] RDMA/cm: Avoid -Wflex-array-member-not-at-end warning
@ 2024-03-25 20:24 Gustavo A. R. Silva
  2024-03-25 22:47 ` Jason Gunthorpe
  0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2024-03-25 20:24 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky
  Cc: linux-rdma, linux-kernel, Gustavo A. R. Silva, linux-hardening

-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]

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/infiniband/core/cm.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index bf0df6ee4f78..80c87085499c 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-02  8:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-25 20:24 [PATCH][next] RDMA/cm: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2024-03-25 22:47 ` Jason Gunthorpe
2024-03-26  2:57   ` Gustavo A. R. Silva
2024-04-02  8:38     ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox