Blob Blame History Raw
From 761e3bd9f5e3aafa95ad3ae50a637dc67c8774f0 Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Thu, 31 Oct 2019 15:15:38 +1100
Subject: [RHEL7.8 PATCH V2 47/47] super-intel: don't mark structs 'packed'
 unnecessarily

super-intel marks a number of structures 'packed', but this
doesn't change the layout - they are already well organized.

This is a problem a gcc warns when code takes the address
of a field in a packet struct - as super-intel sometimes does.

So remove the marking where isn't needed.
Do ensure this does introduce a regression, add a compile-time
assertion that the size of the structure is exactly the value
it had before the 'packed' notation was removed.

Note that a couple of structure do need to be packed.
As the address of fields is never taken, that is safe.

Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
---
 super-intel.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/super-intel.c b/super-intel.c
index 713058c..a7fbed4 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -96,6 +96,19 @@
 						   * mutliple PPL area
 						   */
 
+/*
+ * This macro let's us ensure that no-one accidentally
+ * changes the size of a struct
+ */
+#define ASSERT_SIZE(_struct, size) \
+static inline void __assert_size_##_struct(void)	\
+{							\
+	switch (0) {					\
+	case 0: break;					\
+	case (sizeof(struct _struct) == size): break;	\
+	}						\
+}
+
 /* Disk configuration info. */
 #define IMSM_MAX_DEVICES 255
 struct imsm_disk {
@@ -112,6 +125,7 @@ struct imsm_disk {
 #define	IMSM_DISK_FILLERS	3
 	__u32 filler[IMSM_DISK_FILLERS]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
 };
+ASSERT_SIZE(imsm_disk, 48)
 
 /* map selector for map managment
  */
@@ -146,7 +160,8 @@ struct imsm_map {
 	__u32 disk_ord_tbl[1];	/* disk_ord_tbl[num_members],
 				 * top byte contains some flags
 				 */
-} __attribute__ ((packed));
+};
+ASSERT_SIZE(imsm_map, 52)
 
 struct imsm_vol {
 	__u32 curr_migr_unit;
@@ -169,7 +184,8 @@ struct imsm_vol {
 	__u32 filler[4];
 	struct imsm_map map[1];
 	/* here comes another one if migr_state */
-} __attribute__ ((packed));
+};
+ASSERT_SIZE(imsm_vol, 84)
 
 struct imsm_dev {
 	__u8  volume[MAX_RAID_SERIAL_LEN];
@@ -220,7 +236,8 @@ struct imsm_dev {
 #define IMSM_DEV_FILLERS 3
 	__u32 filler[IMSM_DEV_FILLERS];
 	struct imsm_vol vol;
-} __attribute__ ((packed));
+};
+ASSERT_SIZE(imsm_dev, 164)
 
 struct imsm_super {
 	__u8 sig[MAX_SIGNATURE_LENGTH];	/* 0x00 - 0x1F */
@@ -248,7 +265,8 @@ struct imsm_super {
 	struct imsm_disk disk[1];	/* 0xD8 diskTbl[numDisks] */
 	/* here comes imsm_dev[num_raid_devs] */
 	/* here comes BBM logs */
-} __attribute__ ((packed));
+};
+ASSERT_SIZE(imsm_super, 264)
 
 #define BBM_LOG_MAX_ENTRIES 254
 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256		/* Represents 256 LBAs */
@@ -269,7 +287,8 @@ struct bbm_log {
 	__u32 signature; /* 0xABADB10C */
 	__u32 entry_count;
 	struct bbm_log_entry marked_block_entries[BBM_LOG_MAX_ENTRIES];
-} __attribute__ ((__packed__));
+};
+ASSERT_SIZE(bbm_log, 2040)
 
 static char *map_state_str[] = { "normal", "uninitialized", "degraded", "failed" };
 
@@ -323,7 +342,8 @@ struct migr_record {
 				       * destination - high order 32 bits */
 	__u32 num_migr_units_hi;      /* Total num migration units-of-op
 				       * high order 32 bits */
-} __attribute__ ((__packed__));
+};
+ASSERT_SIZE(migr_record, 64)
 
 struct md_list {
 	/* usage marker:
-- 
2.7.5