From 08f410936a2e5f413c3d06533826a37ea6e0f99c Mon Sep 17 00:00:00 2001 From: Swapnil Pimpale Date: Thu, 13 Mar 2014 16:41:07 +0530 Subject: [PATCH] LU-4674 endianness: Fix __{LITTLE,BIG}_ENDIAN macro usage Fixed the userspace code where __{LITTLE,BIG}_ENDIAN is tested with #ifdef. This patch replaces those checks with #if __BYTE_ORDER == __{LITTLE,BIG}_ENDIAN Signed-off-by: Swapnil Pimpale Change-Id: I92d4cf0c880d8032ea5023cb47ccfe7236dd03ab Reviewed-on: http://review.whamcloud.com/9641 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/user-tcpip.h | 5 +++-- libcfs/libcfs/posix/posix-crc32.c | 3 ++- lnet/klnds/mxlnd/mxlnd_cb.c | 2 +- lustre/include/liblustre.h | 7 ++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libcfs/include/libcfs/user-tcpip.h b/libcfs/include/libcfs/user-tcpip.h index 4997d06..9812fb9 100644 --- a/libcfs/include/libcfs/user-tcpip.h +++ b/libcfs/include/libcfs/user-tcpip.h @@ -42,6 +42,7 @@ #ifndef __KERNEL__ #include +#include /* * Functions to get network interfaces info @@ -97,13 +98,13 @@ int libcfs_sock_create(cfs_socket_t **sockp, int *fatal, ((unsigned char *)&addr)[2], \ ((unsigned char *)&addr)[3] -#if defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN) +#if __BYTE_ORDER == __LITTLE_ENDIAN #define HIPQUAD(addr) \ ((unsigned char *)&addr)[3], \ ((unsigned char *)&addr)[2], \ ((unsigned char *)&addr)[1], \ ((unsigned char *)&addr)[0] -#elif defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) +#elif __BYTE_ORDER == __BIG_ENDIAN #define HIPQUAD NIPQUAD #else #error "Undefined byteorder??" diff --git a/libcfs/libcfs/posix/posix-crc32.c b/libcfs/libcfs/posix/posix-crc32.c index 972c5ff..4937c8c 100644 --- a/libcfs/libcfs/posix/posix-crc32.c +++ b/libcfs/libcfs/posix/posix-crc32.c @@ -2,6 +2,7 @@ * This file contains part of linux kernel implementation of crc32 * kernel version 2.6.32 */ +#include #include #define CRCPOLY_LE 0xedb88320 #define CRC_LE_BITS 8 @@ -34,7 +35,7 @@ unsigned int crc32_le(unsigned int crc, unsigned char const *p, size_t len) const unsigned int *b = (unsigned int *)p; const unsigned int *tab = crc32table_le; -# ifdef __LITTLE_ENDIAN +# if __BYTE_ORDER == __LITTLE_ENDIAN # define DO_CRC(x) crc = tab[(crc ^ (x)) & 255] ^ (crc>>8) # else # define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc<<8) diff --git a/lnet/klnds/mxlnd/mxlnd_cb.c b/lnet/klnds/mxlnd/mxlnd_cb.c index f2a0568..104820c 100644 --- a/lnet/klnds/mxlnd/mxlnd_cb.c +++ b/lnet/klnds/mxlnd/mxlnd_cb.c @@ -855,7 +855,7 @@ mxlnd_ip2nic_id(u32 ip, u64 *nic_id, int tries) if (tmp_id == 0ULL) ret = -EHOSTUNREACH; -#ifdef __LITTLE_ENDIAN +#if __BYTE_ORDER == __LITTLE_ENDIAN *nic_id = ___arch__swab64(tmp_id); #else *nic_id = tmp_id; diff --git a/lustre/include/liblustre.h b/lustre/include/liblustre.h index e0ba5be..4929dd9 100644 --- a/lustre/include/liblustre.h +++ b/lustre/include/liblustre.h @@ -46,6 +46,7 @@ * @{ */ #include +#include #include #ifdef __KERNEL__ @@ -89,7 +90,7 @@ void *inter_module_get(char *arg); static __inline__ int ext2_set_bit(int nr, void *addr) { -#ifdef __BIG_ENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN return set_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr); #else return set_bit(nr, addr); @@ -98,7 +99,7 @@ static __inline__ int ext2_set_bit(int nr, void *addr) static inline int ext2_clear_bit(int nr, void *addr) { -#ifdef __BIG_ENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN return clear_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr); #else return clear_bit(nr, addr); @@ -107,7 +108,7 @@ static inline int ext2_clear_bit(int nr, void *addr) static __inline__ int ext2_test_bit(int nr, void *addr) { -#ifdef __BIG_ENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN __const__ unsigned char *tmp = (__const__ unsigned char *) addr; return (tmp[nr >> 3] >> (nr & 7)) & 1; #else -- 1.8.3.1