Fix warnings of the form:

    libndctl-hpe1.c: In function 'hpe1_smart_valid':
    libndctl-hpe1.c:78:15: warning: dereferencing type-punned pointer will
        break strict-aliasing rules [-Wstrict-aliasing]
        CMD_HPE1(cmd)->gen.nd_family != NVDIMM_FAMILY_HPE1 ||
        ^
    libndctl-hpe1.c:79:15: warning: dereferencing type-punned pointer will
        break strict-aliasing rules [-Wstrict-aliasing]
        CMD_HPE1(cmd)->gen.nd_command != NDN_HPE1_CMD_SMART ||
        ^
    libndctl-hpe1.c: In function 'hpe1_cmd_smart_get_flags':
    libndctl-hpe1.c:93:55: warning: dereferencing type-punned pointer will
        break strict-aliasing rules [-Wstrict-aliasing]
    libndctl-hpe1.c:93:55: warning: dereferencing type-punned pointer will
        break strict-aliasing rules [-Wstrict-aliasing]
    libndctl-hpe1.c: In function 'hpe1_cmd_smart_get_health':
    libndctl-hpe1.c:121:56: warning: dereferencing type-punned pointer will
        break strict-aliasing rules [-Wstrict-aliasing]
    libndctl-hpe1.c:121:56: warning: dereferencing type-punned pointer will
        break strict-aliasing rules [-Wstrict-aliasing]

...for distributions that include "-Wstrict-aliasing" in CFLAGS.

Cc: Brian Boylston <brian.boyls...@hpe.com>
Signed-off-by: Dan Williams <dan.j.willi...@intel.com>
---
 ndctl/lib/libndctl-hpe1.c    |    8 +++-----
 ndctl/lib/libndctl-private.h |    2 ++
 ndctl/lib/ndctl-hpe1.h       |   24 +++++++++++++++---------
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/ndctl/lib/libndctl-hpe1.c b/ndctl/lib/libndctl-hpe1.c
index 48d8e02cf46e..ec542527e509 100644
--- a/ndctl/lib/libndctl-hpe1.c
+++ b/ndctl/lib/libndctl-hpe1.c
@@ -19,11 +19,9 @@
 
 #include "ndctl-hpe1.h"
 
-#define CMD_HPE1(_c) ((struct ndn_pkg_hpe1 *)((_c)->cmd_buf))
-#define CMD_HPE1_SMART(_c) \
-       ((struct ndn_hpe1_smart_data *)(CMD_HPE1(_c)->u.smart.data))
-#define CMD_HPE1_SMART_THRESH(_c) \
-       ((struct ndn_hpe1_smart_threshold_data *)(CMD_HPE1(_c)->u.thresh.data))
+#define CMD_HPE1(_c) ((_c)->hpe1)
+#define CMD_HPE1_SMART(_c) (CMD_HPE1(_c)->u.smart.data)
+#define CMD_HPE1_SMART_THRESH(_c) (CMD_HPE1(_c)->u.thresh.data)
 
 static struct ndctl_cmd *hpe1_dimm_cmd_new_smart(struct ndctl_dimm *dimm)
 {
diff --git a/ndctl/lib/libndctl-private.h b/ndctl/lib/libndctl-private.h
index 4363f2373d7b..0dc9e30cdb6e 100644
--- a/ndctl/lib/libndctl-private.h
+++ b/ndctl/lib/libndctl-private.h
@@ -31,6 +31,7 @@
 #include <ndctl/libndctl.h>
 #include <ccan/endian/endian.h>
 #include <ccan/short_types/short_types.h>
+#include "ndctl-hpe1.h"
 
 #define SZ_16M 0x01000000
 
@@ -191,6 +192,7 @@ struct ndctl_cmd {
 #ifdef HAVE_NDCTL_CLEAR_ERROR
                struct nd_cmd_clear_error clear_err[0];
 #endif
+               struct ndn_pkg_hpe1 hpe1[0];
                struct nd_cmd_smart smart[0];
                struct nd_cmd_smart_threshold smart_t[0];
                struct nd_cmd_get_config_size get_size[0];
diff --git a/ndctl/lib/ndctl-hpe1.h b/ndctl/lib/ndctl-hpe1.h
index 0d41aab4e64f..b050831ec2c4 100644
--- a/ndctl/lib/ndctl-hpe1.h
+++ b/ndctl/lib/ndctl-hpe1.h
@@ -33,12 +33,6 @@ enum {
 };
 
 /* NDN_HPE1_CMD_SMART */
-struct ndn_hpe1_smart {
-       __u32 in_valid_flags;
-       __u32 status;
-       __u8 data[124];
-} __attribute__((packed));
-
 /* ndn_hpe1_smart.in_valid_flags / ndn_hpe1_smart_data.out_valid_flags */
 #define NDN_HPE1_SMART_HEALTH_VALID    (1 << 0)
 #define NDN_HPE1_SMART_TEMP_VALID      (1 << 1)
@@ -112,12 +106,16 @@ struct ndn_hpe1_smart_data {
        __u8    vnd_spec_data[60];
 } __attribute__((packed));
 
-/* NDN_HPE1_CMD_SMART_THRESHOLD */
-struct ndn_hpe1_smart_threshold {
+struct ndn_hpe1_smart {
+       __u32 in_valid_flags;
        __u32 status;
-       __u8 data[32];
+       union {
+               __u8 buf[124];
+               struct ndn_hpe1_smart_data data[0];
+       };
 } __attribute__((packed));
 
+/* NDN_HPE1_CMD_SMART_THRESHOLD */
 struct ndn_hpe1_smart_threshold_data {
        __u16   threshold_alarm_ctl;
        __u16   temp_threshold;
@@ -134,6 +132,14 @@ struct ndn_hpe1_smart_threshold_data {
        __u64   res4;
 } __attribute__((packed));
 
+struct ndn_hpe1_smart_threshold {
+       __u32 status;
+       union {
+               __u8 buf[32];
+               struct ndn_hpe1_smart_threshold_data data[0];
+       };
+} __attribute__((packed));
+
 /* NDN_HPE1_CMD_GET_CONFIG_SIZE */
 struct ndn_hpe1_get_config_size {
        __u32 status;

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to