]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli: Restore RHEL 7 compatibility
authorBart Van Assche <bvanassche@acm.org>
Mon, 24 Jun 2019 13:55:21 +0000 (06:55 -0700)
committerBart Van Assche <bvanassche@acm.org>
Mon, 24 Jun 2019 18:31:20 +0000 (11:31 -0700)
With glibc version 2.24 and before the endianness conversion macros
return a value with an incorrect type. Avoid that this causes the
nvme-cli build to fail on e.g. RHEL 7. A side effect of this patch
is that it allows sparse to verify the type of the endianness
conversion functions.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=16458

Cc: Mikhail Skorzhinskii <mskorzhinskiy@solarflare.com>
Cc: Minwoo Im <minwoo.im.dev@gmail.com>
Reported-by: Mikhail Skorzhinskii <mskorzhinskiy@solarflare.com>
Fixes: e68409e447b2 ("Remove superfluous casts")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
nvme.h

diff --git a/nvme.h b/nvme.h
index a149005a04259de8aa22d46ac41ed7ad5f3de724..f059db864128eb47909ccc97a1b91f04ca649560 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -119,19 +119,31 @@ struct nvme_bar_cap {
 #define __force
 #endif
 
-#define cpu_to_le16(x) \
-       ((__force __le16)htole16(x))
-#define cpu_to_le32(x) \
-       ((__force __le32)htole32(x))
-#define cpu_to_le64(x) \
-       ((__force __le64)htole64(x))
-
-#define le16_to_cpu(x) \
-       le16toh((__force __u16)(x))
-#define le32_to_cpu(x) \
-       le32toh((__force __u32)(x))
-#define le64_to_cpu(x) \
-       le64toh((__force __u64)(x))
+static inline __le16 cpu_to_le16(uint16_t x)
+{
+       return (__force __le16)htole16(x);
+}
+static inline __le32 cpu_to_le32(uint32_t x)
+{
+       return (__force __le32)htole32(x);
+}
+static inline __le64 cpu_to_le64(uint64_t x)
+{
+       return (__force __le64)htole64(x);
+}
+
+static inline uint16_t le16_to_cpu(__le16 x)
+{
+       return le16toh((__force __u16)x);
+}
+static inline uint32_t le32_to_cpu(__le32 x)
+{
+       return le32toh((__force __u32)x);
+}
+static inline uint64_t le64_to_cpu(__le64 x)
+{
+       return le64toh((__force __u64)x);
+}
 
 #define MAX_LIST_ITEMS 256
 struct list_item {