[PATCH] x86: suppress sparse warning in copy_to_user()

From: Johannes Berg
Date: Tue Oct 04 2016 - 03:35:02 EST


From: Johannes Berg <johannes.berg@xxxxxxxxx>

__compiletime_object_size() is simply defined to __builtin_object_size()
which gcc declares with (void *, int type) prototype. This is also done
by sparse, since it follows gcc, which leads it to warn, many times, on
any usage of copy_to_user(), about it:

arch/x86/include/asm/uaccess.h:735:18: warning: incorrect type in argument 1 (different modifiers)
arch/x86/include/asm/uaccess.h:735:18: expected void *<noident>
arch/x86/include/asm/uaccess.h:735:18: got void const *from

Suppress this by adding a (void *) cast. The compiler probably should
have declared it as const, but as it doesn't this is necessary. If it
changes, then the cast also won't matter.

Fixes: 7a3d9b0f3abbe ("x86: Unify copy_to_user() and add size checking to it")
Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx>
---
arch/x86/include/asm/uaccess.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 2131c4ce7d8a..0bd4a5a86199 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -732,7 +732,7 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
static __always_inline unsigned long __must_check
copy_to_user(void __user *to, const void *from, unsigned long n)
{
- int sz = __compiletime_object_size(from);
+ int sz = __compiletime_object_size((void *)from);

kasan_check_read(from, n);

--
2.8.1