diff options
author | Al Viro <viro@ftp.linux.org.uk> | 2007-07-17 03:49:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-17 14:01:07 -0400 |
commit | d37c6e1b67e8d7f3c5fceba491dcb09a15cb7772 (patch) | |
tree | 0475cc3e841e22994b3a779125d4cd90b52dc76d /include/asm-generic/unaligned.h | |
parent | cc040a8a0e8ba95fbb0ae1edcb9ec83623b422e3 (diff) |
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: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/asm-generic/unaligned.h')
-rw-r--r-- | include/asm-generic/unaligned.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h index 09ec447fe2af..16a466e50681 100644 --- a/include/asm-generic/unaligned.h +++ b/include/asm-generic/unaligned.h | |||
@@ -18,7 +18,8 @@ | |||
18 | #define get_unaligned(ptr) \ | 18 | #define get_unaligned(ptr) \ |
19 | __get_unaligned((ptr), sizeof(*(ptr))) | 19 | __get_unaligned((ptr), sizeof(*(ptr))) |
20 | #define put_unaligned(x,ptr) \ | 20 | #define put_unaligned(x,ptr) \ |
21 | __put_unaligned((__u64)(x), (ptr), sizeof(*(ptr))) | 21 | ((void)sizeof(*(ptr)=(x)),\ |
22 | __put_unaligned((__force __u64)(x), (ptr), sizeof(*(ptr)))) | ||
22 | 23 | ||
23 | /* | 24 | /* |
24 | * This function doesn't actually exist. The idea is that when | 25 | * This function doesn't actually exist. The idea is that when |
@@ -95,21 +96,21 @@ static inline void __ustw(__u16 val, __u16 *addr) | |||
95 | default: \ | 96 | default: \ |
96 | bad_unaligned_access_length(); \ | 97 | bad_unaligned_access_length(); \ |
97 | }; \ | 98 | }; \ |
98 | (__typeof__(*(ptr)))val; \ | 99 | (__force __typeof__(*(ptr)))val; \ |
99 | }) | 100 | }) |
100 | 101 | ||
101 | #define __put_unaligned(val, ptr, size) \ | 102 | #define __put_unaligned(val, ptr, size) \ |
102 | do { \ | 103 | ({ \ |
103 | void *__gu_p = ptr; \ | 104 | void *__gu_p = ptr; \ |
104 | switch (size) { \ | 105 | switch (size) { \ |
105 | case 1: \ | 106 | case 1: \ |
106 | *(__u8 *)__gu_p = val; \ | 107 | *(__u8 *)__gu_p = (__force __u8)val; \ |
107 | break; \ | 108 | break; \ |
108 | case 2: \ | 109 | case 2: \ |
109 | __ustw(val, __gu_p); \ | 110 | __ustw((__force __u16)val, __gu_p); \ |
110 | break; \ | 111 | break; \ |
111 | case 4: \ | 112 | case 4: \ |
112 | __ustl(val, __gu_p); \ | 113 | __ustl((__force __u32)val, __gu_p); \ |
113 | break; \ | 114 | break; \ |
114 | case 8: \ | 115 | case 8: \ |
115 | __ustq(val, __gu_p); \ | 116 | __ustq(val, __gu_p); \ |
@@ -117,6 +118,7 @@ do { \ | |||
117 | default: \ | 118 | default: \ |
118 | bad_unaligned_access_length(); \ | 119 | bad_unaligned_access_length(); \ |
119 | }; \ | 120 | }; \ |
120 | } while(0) | 121 | (void)0; \ |
122 | }) | ||
121 | 123 | ||
122 | #endif /* _ASM_GENERIC_UNALIGNED_H */ | 124 | #endif /* _ASM_GENERIC_UNALIGNED_H */ |