Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Adrian Hunter and committed by
Namhyung Kim
3b4fa67f f058fa5b

+9 -8
+9 -8
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
··· 10 10 #include <byteswap.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/compiler.h> 13 + #include <asm-generic/unaligned.h> 13 14 14 15 #include "intel-pt-pkt-decoder.h" 15 16 ··· 79 78 if (len < 8) 80 79 return INTEL_PT_NEED_MORE_BYTES; 81 80 82 - payload = le64_to_cpu(*(uint64_t *)buf); 81 + payload = get_unaligned_le64(buf); 83 82 84 83 for (count = 47; count; count--) { 85 84 if (payload & BIT63) ··· 120 119 if (len < 4) 121 120 return INTEL_PT_NEED_MORE_BYTES; 122 121 packet->type = INTEL_PT_CBR; 123 - packet->payload = le16_to_cpu(*(uint16_t *)(buf + 2)); 122 + packet->payload = get_unaligned_le16(buf + 2); 124 123 return 4; 125 124 } 126 125 ··· 219 218 case 0: 220 219 if (len < 6) 221 220 return INTEL_PT_NEED_MORE_BYTES; 222 - packet->payload = le32_to_cpu(*(uint32_t *)(buf + 2)); 221 + packet->payload = get_unaligned_le32(buf + 2); 223 222 return 6; 224 223 case 1: 225 224 if (len < 10) 226 225 return INTEL_PT_NEED_MORE_BYTES; 227 - packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2)); 226 + packet->payload = get_unaligned_le64(buf + 2); 228 227 return 10; 229 228 default: 230 229 return INTEL_PT_BAD_PACKET; ··· 249 248 if (len < 10) 250 249 return INTEL_PT_NEED_MORE_BYTES; 251 250 packet->type = INTEL_PT_MWAIT; 252 - packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2)); 251 + packet->payload = get_unaligned_le64(buf + 2); 253 252 return 10; 254 253 } 255 254 ··· 456 455 if (len < 3) 457 456 return INTEL_PT_NEED_MORE_BYTES; 458 457 ip_len = 2; 459 - packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1)); 458 + packet->payload = get_unaligned_le16(buf + 1); 460 459 break; 461 460 case 2: 462 461 if (len < 5) 463 462 return INTEL_PT_NEED_MORE_BYTES; 464 463 ip_len = 4; 465 - packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1)); 464 + packet->payload = get_unaligned_le32(buf + 1); 466 465 break; 467 466 case 3: 468 467 case 4: ··· 475 474 if (len < 9) 476 475 return INTEL_PT_NEED_MORE_BYTES; 477 476 ip_len = 8; 478 - packet->payload = le64_to_cpu(*(uint64_t *)(buf + 1)); 477 + packet->payload = get_unaligned_le64(buf + 1); 479 478 break; 480 479 default: 481 480 return INTEL_PT_BAD_PACKET;