Skip to content

Commit 505e428

Browse files
mstsirkinmpe
authored andcommitted
powerpc/uaccess: Allow get_user() with bitwise types
At the moment, if p and x are both of the same bitwise type (eg. __le32), get_user(x, p) produces a sparse warning. This is because *p is loaded into a long then cast back to typeof(*p). When typeof(*p) is a bitwise type (which is uncommon), such a cast needs __force, otherwise sparse produces a warning. For non-bitwise types __force should have no effect, and should not hide any legitimate errors. Note that we are casting to typeof(*p) not typeof(x). Even with the cast, if x and *p are of different types we should get the warning, so I think we are not loosing the ability to detect any actual errors. virtio would like to use bitwise types with get_user() so fix these spurious warnings by adding __force. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> [mpe: Fill in changelog with more details] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent c8742f8 commit 505e428

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎arch/powerpc/include/asm/uaccess.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ do { \
284284
if (!is_kernel_addr((unsigned long)__gu_addr)) \
285285
might_fault(); \
286286
__get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
287-
(x) = (__typeof__(*(ptr)))__gu_val; \
287+
(x) = (__force __typeof__(*(ptr)))__gu_val; \
288288
__gu_err; \
289289
})
290290
#endif /* __powerpc64__ */
@@ -297,7 +297,7 @@ do { \
297297
might_fault(); \
298298
if (access_ok(VERIFY_READ, __gu_addr, (size))) \
299299
__get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
300-
(x) = (__typeof__(*(ptr)))__gu_val; \
300+
(x) = (__force __typeof__(*(ptr)))__gu_val; \
301301
__gu_err; \
302302
})
303303

@@ -308,7 +308,7 @@ do { \
308308
const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
309309
__chk_user_ptr(ptr); \
310310
__get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
311-
(x) = (__typeof__(*(ptr)))__gu_val; \
311+
(x) = (__force __typeof__(*(ptr)))__gu_val; \
312312
__gu_err; \
313313
})
314314

0 commit comments

Comments
 (0)