[PATCH rdma-core] srp_daemon: Reorganize ib_mad_notice_attr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To avoid a gcc 8 warning:

../srp_daemon/srp_ib_types.h:215:3: warning: alignment 1 of ‘struct _ntc_64_67’ is less than 4 [-Wpacked-not-aligned]
       } PACK_SUFFIX ntc_64_67;
       ^
../srp_daemon/srp_ib_types.h:214:19: warning: ‘gid’ offset 6 in ‘struct _ntc_64_67’ isn’t aligned to 4 [-Wpacked-not-aligned]
       union umad_gid gid; // the Node or Multicast Group that came in/out

This requires making the sub structures in the union aligned to a natural
point, by absorbing the common member in the union sub structures. Then
the compiler can see the alignment of everything is natural and packed is
also no longer required at all.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
---
 srp_daemon/srp_daemon.c       |  6 +++++-
 srp_daemon/srp_handle_traps.c |  8 ++++----
 srp_daemon/srp_ib_types.h     | 34 +++++++++++++++++++---------------
 3 files changed, 28 insertions(+), 20 deletions(-)

Leon this replaces your 'cmake; Mask packed-not-aligned GCC warnings'
patch in your FC28 series.

Bart, this is a bit of a rework, are you OK with it? It results in the
same offsets as far as I could see.

diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c
index 1040fefd660502..78f2436384e9ed 100644
--- a/srp_daemon/srp_daemon.c
+++ b/srp_daemon/srp_daemon.c
@@ -2103,8 +2103,12 @@ int main(int argc, char *argv[])
 	BUILD_ASSERT(sizeof(struct ib_path_rec) == 64);
 	BUILD_ASSERT(sizeof(struct ib_inform_info) == 36);
 	BUILD_ASSERT(sizeof(struct ib_mad_notice_attr) == 80);
+	BUILD_ASSERT(offsetof(struct ib_mad_notice_attr, generic.trap_num) ==
+		     4);
+	BUILD_ASSERT(offsetof(struct ib_mad_notice_attr, vend.dev_id) == 4);
+	BUILD_ASSERT(offsetof(struct ib_mad_notice_attr, ntc_64_67.gid) == 16);
 	BUILD_ASSERT(offsetof(struct ib_mad_notice_attr,
-			      data_details.ntc_64_67.gid) == 16);
+			      ntc_144.new_cap_mask) == 16);
 #endif
 	BUILD_ASSERT(sizeof(struct srp_sa_node_rec) == 108);
 	BUILD_ASSERT(sizeof(struct srp_sa_port_info_rec) == 58);
diff --git a/srp_daemon/srp_handle_traps.c b/srp_daemon/srp_handle_traps.c
index f902eb4632f15d..d4ea252a42b936 100644
--- a/srp_daemon/srp_handle_traps.c
+++ b/srp_daemon/srp_handle_traps.c
@@ -768,16 +768,16 @@ static int get_trap_notices(struct resources *res)
 			}
 
 			notice_buffer = (struct ib_mad_notice_attr *) (mad_buffer->data);
-			trap_num = be16toh(notice_buffer->g_or_v.generic.trap_num);
+			trap_num = be16toh(notice_buffer->generic.trap_num);
 			response_to_trap(res->sync_res, res->ud_res, mad_buffer);
 			if (trap_num == UMAD_SM_GID_IN_SERVICE_TRAP)
 				push_gid_to_list(res->sync_res,
-						 &notice_buffer->data_details.ntc_64_67.gid,
+						 &notice_buffer->ntc_64_67.gid,
 						 pkey);
 			else if (trap_num == UMAD_SM_LOCAL_CHANGES_TRAP) {
-				if (be32toh(notice_buffer->data_details.ntc_144.new_cap_mask) & SRP_IS_DM)
+				if (be32toh(notice_buffer->ntc_144.new_cap_mask) & SRP_IS_DM)
 					push_lid_to_list(res->sync_res,
-							 be16toh(notice_buffer->data_details.ntc_144.lid),
+							 be16toh(notice_buffer->ntc_144.lid),
 							 pkey);
 			} else {
 				pr_err("Unhandled trap_num %d\n", trap_num);
diff --git a/srp_daemon/srp_ib_types.h b/srp_daemon/srp_ib_types.h
index 8fa19a762377d9..0aacdd3efdc865 100644
--- a/srp_daemon/srp_ib_types.h
+++ b/srp_daemon/srp_ib_types.h
@@ -179,53 +179,57 @@ struct ib_inform_info
 
 struct ib_mad_notice_attr		// Total Size calc  Accumulated
 {
-	uint8_t		generic_type;		// 1		1
-
-	union _notice_g_or_v
+	union
 	{
-		struct _notice_generic		// 5		6
+		uint8_t	generic_type;	// 1		1
+
+		struct _notice_generic
 		{
+			uint8_t		generic_type;
 			uint8_t		prod_type_msb;
 			__be16		prod_type_lsb;
 			__be16		trap_num;
-		} PACK_SUFFIX generic;
+		} generic;
 
 		struct _notice_vend
 		{
+			uint8_t		generic_type;
 			uint8_t		vend_id_msb;
 			__be16		vend_id_lsb;
 			__be16		dev_id;
-		} PACK_SUFFIX vend;
-	} g_or_v;
+		} vend;
+	};
 
-	__be16		issuer_lid;		// 2		8
-	__be16		toggle_count;		// 2		10
+	__be16 issuer_lid;		// 2		8
 
-	union _data_details			// 54		64
+	union				// 54		64
 	{
+		__be16		toggle_count;		// 2		10
 		struct _raw_data
 		{
+			__be16  toggle_count;
 			uint8_t	details[54];
 		} raw_data;
 
 		struct _ntc_64_67
 		{
+			__be16		toggle_count;
 			uint8_t		res[6];
 			union umad_gid	gid;	// the Node or Multicast Group that came in/out
-		} PACK_SUFFIX ntc_64_67;
+		} ntc_64_67;
 
 		struct _ntc_144 {
+			__be16		toggle_count;
 			__be16		pad1;
 			__be16		lid;		// lid where capability mask changed
 			__be16		pad2;
 			__be32		new_cap_mask;	// new capability mask
-		} PACK_SUFFIX ntc_144;
-
-	} data_details;
+		} ntc_144;
+	};
 
 	union umad_gid			issuer_gid;	// 16		80
 
-} PACK_SUFFIX4;
+};
 
 /****f* IBA Base: Types/ib_gid_get_guid
 * NAME
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux