From c83287d20e29eb11e7766b84067bd4c2fcfb2449 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 20 Mar 2014 11:42:27 -0300 Subject: [PATCH] shared: Add get_le16() Add helper to avoid possible unaligned memory access when handling uint16 value using little-endian representation. --- src/shared/util.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shared/util.h b/src/shared/util.h index a12927282..ef845ae40 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -101,6 +101,11 @@ static inline void bswap_128(const void *src, void *dst) d[15 - i] = s[i]; } +static inline uint16_t get_le16(const void *ptr) +{ + return le16_to_cpu(get_unaligned((const uint16_t *) ptr)); +} + static inline void put_le16(uint16_t val, void *dst) { put_unaligned(cpu_to_le16(val), (uint16_t *) dst); -- 2.11.0