#include <byteswap.h>
 #include <linux/kernel.h>
 #include <linux/compiler.h>
+#include <asm-generic/unaligned.h>
 
 #include "intel-pt-pkt-decoder.h"
 
        if (len < 8)
                return INTEL_PT_NEED_MORE_BYTES;
 
-       payload = le64_to_cpu(*(uint64_t *)buf);
+       payload = get_unaligned_le64(buf);
 
        for (count = 47; count; count--) {
                if (payload & BIT63)
        if (len < 4)
                return INTEL_PT_NEED_MORE_BYTES;
        packet->type = INTEL_PT_CBR;
-       packet->payload = le16_to_cpu(*(uint16_t *)(buf + 2));
+       packet->payload = get_unaligned_le16(buf + 2);
        return 4;
 }
 
        case 0:
                if (len < 6)
                        return INTEL_PT_NEED_MORE_BYTES;
-               packet->payload = le32_to_cpu(*(uint32_t *)(buf + 2));
+               packet->payload = get_unaligned_le32(buf + 2);
                return 6;
        case 1:
                if (len < 10)
                        return INTEL_PT_NEED_MORE_BYTES;
-               packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+               packet->payload = get_unaligned_le64(buf + 2);
                return 10;
        default:
                return INTEL_PT_BAD_PACKET;
        if (len < 10)
                return INTEL_PT_NEED_MORE_BYTES;
        packet->type = INTEL_PT_MWAIT;
-       packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+       packet->payload = get_unaligned_le64(buf + 2);
        return 10;
 }
 
                if (len < 3)
                        return INTEL_PT_NEED_MORE_BYTES;
                ip_len = 2;
-               packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1));
+               packet->payload = get_unaligned_le16(buf + 1);
                break;
        case 2:
                if (len < 5)
                        return INTEL_PT_NEED_MORE_BYTES;
                ip_len = 4;
-               packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1));
+               packet->payload = get_unaligned_le32(buf + 1);
                break;
        case 3:
        case 4:
                if (len < 9)
                        return INTEL_PT_NEED_MORE_BYTES;
                ip_len = 8;
-               packet->payload = le64_to_cpu(*(uint64_t *)(buf + 1));
+               packet->payload = get_unaligned_le64(buf + 1);
                break;
        default:
                return INTEL_PT_BAD_PACKET;