This fixes "taking address of packed member ... may result in an
unaligned pointer value [-Waddress-of-packed-member]" warnings from gcc.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 clock.c | 4 +++-
 msg.c   | 7 ++++++-
 tlv.c   | 6 +++---
 util.h  | 2 +-
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/clock.c b/clock.c
index 7005636..f88df58 100644
--- a/clock.c
+++ b/clock.c
@@ -350,6 +350,7 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
        struct time_status_np *tsn;
        struct tlv_extra *extra;
        struct PTPText *text;
+       uint16_t duration;
        int datalen = 0;
 
        extra = tlv_extra_alloc();
@@ -452,7 +453,8 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
                        break;
                }
                sen = (struct subscribe_events_np *)tlv->data;
-               clock_get_subscription(c, req, sen->bitmask, &sen->duration);
+               clock_get_subscription(c, req, sen->bitmask, &duration);
+               memcpy(&sen->duration, &duration, sizeof(sen->duration));
                datalen = sizeof(*sen);
                break;
        case TLV_SYNCHRONIZATION_UNCERTAIN_NP:
diff --git a/msg.c b/msg.c
index c4516ad..717fbdd 100644
--- a/msg.c
+++ b/msg.c
@@ -19,6 +19,7 @@
 #include <arpa/inet.h>
 #include <errno.h>
 #include <malloc.h>
+#include <stdlib.h>
 #include <string.h>
 #include <time.h>
 
@@ -37,7 +38,7 @@ int assume_two_step = 0;
 struct message_storage {
        unsigned char reserved[MSG_HEADROOM];
        struct ptp_message msg;
-} PACKED;
+};
 
 static TAILQ_HEAD(msg_pool, ptp_message) msg_pool = 
TAILQ_HEAD_INITIALIZER(msg_pool);
 
@@ -267,6 +268,10 @@ struct ptp_message *msg_allocate(void)
                        pool_stats.total++;
                        pool_debug("allocate", m);
                }
+               if (sizeof(s->reserved) + sizeof(s->msg) != sizeof(*s)) {
+                   pr_err("unexpected alignment");
+                   exit(1);
+               }
        }
        if (m) {
                memset(m, 0, sizeof(*m));
diff --git a/tlv.c b/tlv.c
index 879bb7e..98ef6e1 100644
--- a/tlv.c
+++ b/tlv.c
@@ -67,7 +67,7 @@ static void timestamp_net2host(struct Timestamp *t)
        NTOHL(t->nanoseconds);
 }
 
-static uint16_t flip16(uint16_t *p)
+static uint16_t flip16(void *p)
 {
        uint16_t v;
        memcpy(&v, p, sizeof(v));
@@ -76,7 +76,7 @@ static uint16_t flip16(uint16_t *p)
        return v;
 }
 
-static int64_t host2net64_unaligned(int64_t *p)
+static int64_t host2net64_unaligned(void *p)
 {
        int64_t v;
        memcpy(&v, p, sizeof(v));
@@ -85,7 +85,7 @@ static int64_t host2net64_unaligned(int64_t *p)
        return v;
 }
 
-static int64_t net2host64_unaligned(int64_t *p)
+static int64_t net2host64_unaligned(void *p)
 {
        int64_t v;
        memcpy(&v, p, sizeof(v));
diff --git a/util.h b/util.h
index 41e33d4..739c8fd 100644
--- a/util.h
+++ b/util.h
@@ -57,7 +57,7 @@ const char *ts_str(enum timestamp_type ts);
  */
 int addreq(enum transport_type type, struct address *a, struct address *b);
 
-static inline uint16_t align16(uint16_t *p)
+static inline uint16_t align16(void *p)
 {
        uint16_t v;
        memcpy(&v, p, sizeof(v));
-- 
2.26.2



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to