From: Jens Axboe Date: Tue, 1 Jul 2014 14:46:44 +0000 (-0600) Subject: Add a typecheck for the endianness conversions X-Git-Tag: fio-2.1.11~39 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=ff8039b745d59ede0ce9245ed24da14ecf2d3f38 Add a typecheck for the endianness conversions Signed-off-by: Jens Axboe --- diff --git a/compiler/compiler.h b/compiler/compiler.h index 0a0213b6..e1afcb42 100644 --- a/compiler/compiler.h +++ b/compiler/compiler.h @@ -22,4 +22,15 @@ #define fio_unlikely(x) __builtin_expect(!!(x), 0) +/* + * Check at compile time that something is of a particular type. + * Always evaluates to 1 so you may use it easily in comparisons. + */ +#define typecheck(type,x) \ +({ type __dummy; \ + typeof(x) __dummy2; \ + (void)(&__dummy == &__dummy2); \ + 1; \ +}) + #endif diff --git a/os/os.h b/os/os.h index b8eee66a..df706ab7 100644 --- a/os/os.h +++ b/os/os.h @@ -202,23 +202,29 @@ static inline uint64_t fio_swap64(uint64_t val) #ifdef FIO_INTERNAL #define le16_to_cpu(val) ({ \ + typecheck(uint16_t, val); \ __le16_to_cpu(val); \ }) #define le32_to_cpu(val) ({ \ + typecheck(uint32_t, val); \ __le32_to_cpu(val); \ }) #define le64_to_cpu(val) ({ \ - __le64_to_cpu(val); \ + typecheck(uint64_t, val); \ + __le64_to_cpu(val); \ }) #endif #define cpu_to_le16(val) ({ \ + typecheck(uint16_t, val); \ __cpu_to_le16(val); \ }) #define cpu_to_le32(val) ({ \ + typecheck(uint32_t, val); \ __cpu_to_le32(val); \ }) #define cpu_to_le64(val) ({ \ + typecheck(uint64_t, val); \ __cpu_to_le64(val); \ })