dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/0047-super-intel-don-t-mark-structs-packed-unnecessarily.patch

f5dd7b
From 761e3bd9f5e3aafa95ad3ae50a637dc67c8774f0 Mon Sep 17 00:00:00 2001
f5dd7b
From: NeilBrown <neilb@suse.de>
f5dd7b
Date: Thu, 31 Oct 2019 15:15:38 +1100
f5dd7b
Subject: [RHEL7.8 PATCH V2 47/47] super-intel: don't mark structs 'packed'
f5dd7b
 unnecessarily
f5dd7b
f5dd7b
super-intel marks a number of structures 'packed', but this
f5dd7b
doesn't change the layout - they are already well organized.
f5dd7b
f5dd7b
This is a problem a gcc warns when code takes the address
f5dd7b
of a field in a packet struct - as super-intel sometimes does.
f5dd7b
f5dd7b
So remove the marking where isn't needed.
f5dd7b
Do ensure this does introduce a regression, add a compile-time
f5dd7b
assertion that the size of the structure is exactly the value
f5dd7b
it had before the 'packed' notation was removed.
f5dd7b
f5dd7b
Note that a couple of structure do need to be packed.
f5dd7b
As the address of fields is never taken, that is safe.
f5dd7b
f5dd7b
Signed-off-by: NeilBrown <neilb@suse.de>
f5dd7b
Acked-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
f5dd7b
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
f5dd7b
---
f5dd7b
 super-intel.c | 32 ++++++++++++++++++++++++++------
f5dd7b
 1 file changed, 26 insertions(+), 6 deletions(-)
f5dd7b
f5dd7b
diff --git a/super-intel.c b/super-intel.c
f5dd7b
index 713058c..a7fbed4 100644
f5dd7b
--- a/super-intel.c
f5dd7b
+++ b/super-intel.c
f5dd7b
@@ -96,6 +96,19 @@
f5dd7b
 						   * mutliple PPL area
f5dd7b
 						   */
f5dd7b
 
f5dd7b
+/*
f5dd7b
+ * This macro let's us ensure that no-one accidentally
f5dd7b
+ * changes the size of a struct
f5dd7b
+ */
f5dd7b
+#define ASSERT_SIZE(_struct, size) \
f5dd7b
+static inline void __assert_size_##_struct(void)	\
f5dd7b
+{							\
f5dd7b
+	switch (0) {					\
f5dd7b
+	case 0: break;					\
f5dd7b
+	case (sizeof(struct _struct) == size): break;	\
f5dd7b
+	}						\
f5dd7b
+}
f5dd7b
+
f5dd7b
 /* Disk configuration info. */
f5dd7b
 #define IMSM_MAX_DEVICES 255
f5dd7b
 struct imsm_disk {
f5dd7b
@@ -112,6 +125,7 @@ struct imsm_disk {
f5dd7b
 #define	IMSM_DISK_FILLERS	3
f5dd7b
 	__u32 filler[IMSM_DISK_FILLERS]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
f5dd7b
 };
f5dd7b
+ASSERT_SIZE(imsm_disk, 48)
f5dd7b
 
f5dd7b
 /* map selector for map managment
f5dd7b
  */
f5dd7b
@@ -146,7 +160,8 @@ struct imsm_map {
f5dd7b
 	__u32 disk_ord_tbl[1];	/* disk_ord_tbl[num_members],
f5dd7b
 				 * top byte contains some flags
f5dd7b
 				 */
f5dd7b
-} __attribute__ ((packed));
f5dd7b
+};
f5dd7b
+ASSERT_SIZE(imsm_map, 52)
f5dd7b
 
f5dd7b
 struct imsm_vol {
f5dd7b
 	__u32 curr_migr_unit;
f5dd7b
@@ -169,7 +184,8 @@ struct imsm_vol {
f5dd7b
 	__u32 filler[4];
f5dd7b
 	struct imsm_map map[1];
f5dd7b
 	/* here comes another one if migr_state */
f5dd7b
-} __attribute__ ((packed));
f5dd7b
+};
f5dd7b
+ASSERT_SIZE(imsm_vol, 84)
f5dd7b
 
f5dd7b
 struct imsm_dev {
f5dd7b
 	__u8  volume[MAX_RAID_SERIAL_LEN];
f5dd7b
@@ -220,7 +236,8 @@ struct imsm_dev {
f5dd7b
 #define IMSM_DEV_FILLERS 3
f5dd7b
 	__u32 filler[IMSM_DEV_FILLERS];
f5dd7b
 	struct imsm_vol vol;
f5dd7b
-} __attribute__ ((packed));
f5dd7b
+};
f5dd7b
+ASSERT_SIZE(imsm_dev, 164)
f5dd7b
 
f5dd7b
 struct imsm_super {
f5dd7b
 	__u8 sig[MAX_SIGNATURE_LENGTH];	/* 0x00 - 0x1F */
f5dd7b
@@ -248,7 +265,8 @@ struct imsm_super {
f5dd7b
 	struct imsm_disk disk[1];	/* 0xD8 diskTbl[numDisks] */
f5dd7b
 	/* here comes imsm_dev[num_raid_devs] */
f5dd7b
 	/* here comes BBM logs */
f5dd7b
-} __attribute__ ((packed));
f5dd7b
+};
f5dd7b
+ASSERT_SIZE(imsm_super, 264)
f5dd7b
 
f5dd7b
 #define BBM_LOG_MAX_ENTRIES 254
f5dd7b
 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256		/* Represents 256 LBAs */
f5dd7b
@@ -269,7 +287,8 @@ struct bbm_log {
f5dd7b
 	__u32 signature; /* 0xABADB10C */
f5dd7b
 	__u32 entry_count;
f5dd7b
 	struct bbm_log_entry marked_block_entries[BBM_LOG_MAX_ENTRIES];
f5dd7b
-} __attribute__ ((__packed__));
f5dd7b
+};
f5dd7b
+ASSERT_SIZE(bbm_log, 2040)
f5dd7b
 
f5dd7b
 static char *map_state_str[] = { "normal", "uninitialized", "degraded", "failed" };
f5dd7b
 
f5dd7b
@@ -323,7 +342,8 @@ struct migr_record {
f5dd7b
 				       * destination - high order 32 bits */
f5dd7b
 	__u32 num_migr_units_hi;      /* Total num migration units-of-op
f5dd7b
 				       * high order 32 bits */
f5dd7b
-} __attribute__ ((__packed__));
f5dd7b
+};
f5dd7b
+ASSERT_SIZE(migr_record, 64)
f5dd7b
 
f5dd7b
 struct md_list {
f5dd7b
 	/* usage marker:
f5dd7b
-- 
f5dd7b
2.7.5
f5dd7b