aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2023-10-05 22:04:50 +0300
committerNamhyung Kim <namhyung@kernel.org>2023-10-17 12:40:49 -0700
commit3b4fa67fc666eb88ae4c0ffdfbe338bec989fbee (patch)
treefc83b6b541e78293f4bd29467a2bec794d03bacd
parentf058fa5b07556abed26e5ae9d8e8ad13f79e1fa2 (diff)
downloadlinux-3b4fa67fc666eb88ae4c0ffdfbe338bec989fbee.tar.gz
perf intel-pt: Use get_unaligned_le16() etc
Avoid unaligned access by using get_unaligned_le16(), get_unaligned_le32() and get_unaligned_le64(). Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20231005190451.175568-5-adrian.hunter@intel.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index ffd0d647473c18..7a90218aecb15a 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -10,6 +10,7 @@
#include <byteswap.h>
#include <linux/kernel.h>
#include <linux/compiler.h>
+#include <asm-generic/unaligned.h>
#include "intel-pt-pkt-decoder.h"
@@ -78,7 +79,7 @@ static int intel_pt_get_long_tnt(const unsigned char *buf, size_t len,
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)
@@ -119,7 +120,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len,
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;
}
@@ -218,12 +219,12 @@ static int intel_pt_get_ptwrite(const unsigned char *buf, size_t len,
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;
@@ -248,7 +249,7 @@ static int intel_pt_get_mwait(const unsigned char *buf, size_t len,
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;
}
@@ -455,13 +456,13 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte,
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:
@@ -474,7 +475,7 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte,
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;