Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Al Viro and committed by
Linus Torvalds
60262e58 e7cf261b

+12 -10
+12 -10
include/asm-arm/unaligned.h
··· 60 60 __get_unaligned_4_be((__p+4))) 61 61 62 62 #define __get_unaligned_le(ptr) \ 63 - ({ \ 63 + ((__force typeof(*(ptr)))({ \ 64 64 const __u8 *__p = (const __u8 *)(ptr); \ 65 65 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \ 66 66 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_le(__p), \ 67 67 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_le(__p), \ 68 68 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_le(__p), \ 69 69 (void)__bug_unaligned_x(__p))))); \ 70 - }) 70 + })) 71 71 72 72 #define __get_unaligned_be(ptr) \ 73 - ({ \ 73 + ((__force typeof(*(ptr)))({ \ 74 74 const __u8 *__p = (const __u8 *)(ptr); \ 75 75 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \ 76 76 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_be(__p), \ 77 77 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_be(__p), \ 78 78 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_be(__p), \ 79 79 (void)__bug_unaligned_x(__p))))); \ 80 - }) 80 + })) 81 81 82 82 83 83 static inline void __put_unaligned_2_le(__u32 __v, register __u8 *__p) ··· 131 131 */ 132 132 #define __put_unaligned_le(val,ptr) \ 133 133 ({ \ 134 + (void)sizeof(*(ptr) = (val)); \ 134 135 switch (sizeof(*(ptr))) { \ 135 136 case 1: \ 136 137 *(ptr) = (val); \ 137 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 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 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 144 break; \ 144 145 default: __bug_unaligned_x(ptr); \ 145 146 break; \ ··· 150 149 151 150 #define __put_unaligned_be(val,ptr) \ 152 151 ({ \ 152 + (void)sizeof(*(ptr) = (val)); \ 153 153 switch (sizeof(*(ptr))) { \ 154 154 case 1: \ 155 155 *(ptr) = (val); \ 156 156 break; \ 157 - case 2: __put_unaligned_2_be((val),(__u8 *)(ptr)); \ 157 + case 2: __put_unaligned_2_be((__force u16)(val),(__u8 *)(ptr)); \ 158 158 break; \ 159 - case 4: __put_unaligned_4_be((val),(__u8 *)(ptr)); \ 159 + case 4: __put_unaligned_4_be((__force u32)(val),(__u8 *)(ptr)); \ 160 160 break; \ 161 - case 8: __put_unaligned_8_be((val),(__u8 *)(ptr)); \ 161 + case 8: __put_unaligned_8_be((__force u64)(val),(__u8 *)(ptr)); \ 162 162 break; \ 163 163 default: __bug_unaligned_x(ptr); \ 164 164 break; \