aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-arm/unaligned.h
diff options
context:
space:
mode:
authorAl Viro <viro@ftp.linux.org.uk>2007-07-26 12:46:19 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-26 14:11:57 -0400
commit60262e58e305f27d05eefeda172117521514f364 (patch)
tree5922886821cecd727554b8e8b0544bc01b6b985e /include/asm-arm/unaligned.h
parente7cf261b447ed7edbf7c10c046e078bda799afaf (diff)
arm unaligned.h annotations
Have put_unaligned() warn if types would be wrong for assignment, slap force-casts where needed. Cast the result of get_unaligned to typeof(*ptr). With that in place we get proper typechecking, both from gcc and from sparse, including that for bitwise types. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/asm-arm/unaligned.h')
-rw-r--r--include/asm-arm/unaligned.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/include/asm-arm/unaligned.h b/include/asm-arm/unaligned.h
index 795b9e5b9e6a..8431f6eed5c6 100644
--- a/include/asm-arm/unaligned.h
+++ b/include/asm-arm/unaligned.h
@@ -60,24 +60,24 @@ extern int __bug_unaligned_x(const void *ptr);
60 __get_unaligned_4_be((__p+4))) 60 __get_unaligned_4_be((__p+4)))
61 61
62#define __get_unaligned_le(ptr) \ 62#define __get_unaligned_le(ptr) \
63 ({ \ 63 ((__force typeof(*(ptr)))({ \
64 const __u8 *__p = (const __u8 *)(ptr); \ 64 const __u8 *__p = (const __u8 *)(ptr); \
65 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \ 65 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \
66 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_le(__p), \ 66 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_le(__p), \
67 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_le(__p), \ 67 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_le(__p), \
68 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_le(__p), \ 68 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_le(__p), \
69 (void)__bug_unaligned_x(__p))))); \ 69 (void)__bug_unaligned_x(__p))))); \
70 }) 70 }))
71 71
72#define __get_unaligned_be(ptr) \ 72#define __get_unaligned_be(ptr) \
73 ({ \ 73 ((__force typeof(*(ptr)))({ \
74 const __u8 *__p = (const __u8 *)(ptr); \ 74 const __u8 *__p = (const __u8 *)(ptr); \
75 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \ 75 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \
76 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_be(__p), \ 76 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_be(__p), \
77 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_be(__p), \ 77 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_be(__p), \
78 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_be(__p), \ 78 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_be(__p), \
79 (void)__bug_unaligned_x(__p))))); \ 79 (void)__bug_unaligned_x(__p))))); \
80 }) 80 }))
81 81
82 82
83static inline void __put_unaligned_2_le(__u32 __v, register __u8 *__p) 83static inline void __put_unaligned_2_le(__u32 __v, register __u8 *__p)
@@ -131,15 +131,16 @@ static inline void __put_unaligned_8_be(const unsigned long long __v, register _
131 */ 131 */
132#define __put_unaligned_le(val,ptr) \ 132#define __put_unaligned_le(val,ptr) \
133 ({ \ 133 ({ \
134 (void)sizeof(*(ptr) = (val)); \
134 switch (sizeof(*(ptr))) { \ 135 switch (sizeof(*(ptr))) { \
135 case 1: \ 136 case 1: \
136 *(ptr) = (val); \ 137 *(ptr) = (val); \
137 break; \ 138 break; \
138 case 2: __put_unaligned_2_le((val),(__u8 *)(ptr)); \ 139 case 2: __put_unaligned_2_le((__force u16)(val),(__u8 *)(ptr)); \
139 break; \ 140 break; \
140 case 4: __put_unaligned_4_le((val),(__u8 *)(ptr)); \ 141 case 4: __put_unaligned_4_le((__force u32)(val),(__u8 *)(ptr)); \
141 break; \ 142 break; \
142 case 8: __put_unaligned_8_le((val),(__u8 *)(ptr)); \ 143 case 8: __put_unaligned_8_le((__force u64)(val),(__u8 *)(ptr)); \
143 break; \ 144 break; \
144 default: __bug_unaligned_x(ptr); \ 145 default: __bug_unaligned_x(ptr); \
145 break; \ 146 break; \
@@ -149,15 +150,16 @@ static inline void __put_unaligned_8_be(const unsigned long long __v, register _
149 150
150#define __put_unaligned_be(val,ptr) \ 151#define __put_unaligned_be(val,ptr) \
151 ({ \ 152 ({ \
153 (void)sizeof(*(ptr) = (val)); \
152 switch (sizeof(*(ptr))) { \ 154 switch (sizeof(*(ptr))) { \
153 case 1: \ 155 case 1: \
154 *(ptr) = (val); \ 156 *(ptr) = (val); \
155 break; \ 157 break; \
156 case 2: __put_unaligned_2_be((val),(__u8 *)(ptr)); \ 158 case 2: __put_unaligned_2_be((__force u16)(val),(__u8 *)(ptr)); \
157 break; \ 159 break; \
158 case 4: __put_unaligned_4_be((val),(__u8 *)(ptr)); \ 160 case 4: __put_unaligned_4_be((__force u32)(val),(__u8 *)(ptr)); \
159 break; \ 161 break; \
160 case 8: __put_unaligned_8_be((val),(__u8 *)(ptr)); \ 162 case 8: __put_unaligned_8_be((__force u64)(val),(__u8 *)(ptr)); \
161 break; \ 163 break; \
162 default: __bug_unaligned_x(ptr); \ 164 default: __bug_unaligned_x(ptr); \
163 break; \ 165 break; \