Commit d37c6e1b authored by Al Viro's avatar Al Viro Committed by Linus Torvalds

saner typechecking in generic unaligned.h

Verify that types would match for assignment (under sizeof, so we are safe from
side effects or any code actually getting generated), then explicitly cast
everywhere to the fixed-sized types.  Kills a bunch of bogus warnings about
constants being truncated (gcc, sparse), finds a pile of endianness problems
hidden by old noise (sparse).
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent cc040a8a
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#define get_unaligned(ptr) \ #define get_unaligned(ptr) \
__get_unaligned((ptr), sizeof(*(ptr))) __get_unaligned((ptr), sizeof(*(ptr)))
#define put_unaligned(x,ptr) \ #define put_unaligned(x,ptr) \
__put_unaligned((__u64)(x), (ptr), sizeof(*(ptr))) ((void)sizeof(*(ptr)=(x)),\
__put_unaligned((__force __u64)(x), (ptr), sizeof(*(ptr))))
/* /*
* This function doesn't actually exist. The idea is that when * This function doesn't actually exist. The idea is that when
...@@ -95,21 +96,21 @@ static inline void __ustw(__u16 val, __u16 *addr) ...@@ -95,21 +96,21 @@ static inline void __ustw(__u16 val, __u16 *addr)
default: \ default: \
bad_unaligned_access_length(); \ bad_unaligned_access_length(); \
}; \ }; \
(__typeof__(*(ptr)))val; \ (__force __typeof__(*(ptr)))val; \
}) })
#define __put_unaligned(val, ptr, size) \ #define __put_unaligned(val, ptr, size) \
do { \ ({ \
void *__gu_p = ptr; \ void *__gu_p = ptr; \
switch (size) { \ switch (size) { \
case 1: \ case 1: \
*(__u8 *)__gu_p = val; \ *(__u8 *)__gu_p = (__force __u8)val; \
break; \ break; \
case 2: \ case 2: \
__ustw(val, __gu_p); \ __ustw((__force __u16)val, __gu_p); \
break; \ break; \
case 4: \ case 4: \
__ustl(val, __gu_p); \ __ustl((__force __u32)val, __gu_p); \
break; \ break; \
case 8: \ case 8: \
__ustq(val, __gu_p); \ __ustq(val, __gu_p); \
...@@ -117,6 +118,7 @@ do { \ ...@@ -117,6 +118,7 @@ do { \
default: \ default: \
bad_unaligned_access_length(); \ bad_unaligned_access_length(); \
}; \ }; \
} while(0) (void)0; \
})
#endif /* _ASM_GENERIC_UNALIGNED_H */ #endif /* _ASM_GENERIC_UNALIGNED_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment