powerpc/sparse: constify addresses in get_user macros
cover powerpc/sparse: constify addresses in get_user macros
Looking through the sparse warnings, I noticed that we were getting warnings about dropping const qualifiers in get_user calls. This took a while to figure out: it turns out that if you pass a const pointer in, sparse will complain when we drop the const qualifier deep inside the __get_user_ macros. This simple series fixes that, squashing over 60 warnings.
Daniel Axtens (3):
powerpc/sparse: constify the address pointer in __get_user_check powerpc/sparse: constify the address pointer in __get_user_nocheck powerpc/sparse: constify the address pointer in __get_user_nosleep
arch/powerpc/include/asm/uaccess.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/3 powerpc/sparse: constify the address pointer in __get_user_check
In __get_user_check, we create an intermediate pointer for the user address we're about to fetch. We currently don't tag this pointer as const. Make it const, as we are simply dereferencing it, and it's scope is limited to the __get_user_check macro.
---
This fixes warnings outside arch/powerpc where people are passing constified pointers into get_user(), such as:
linux/fs/exec.c:423:21: warning: incorrect type in initializer (different modifiers)
expected unsigned int [noderef] <asn:1>*__gu_addr
got unsigned int const [noderef] [usertype] <asn:1>*
linux/kernel/trace/trace.c:1219:15: warning: incorrect type in initializer (different modifiers)
expected char [noderef] <asn:1>*__gu_addr
got char const [noderef] <asn:1>*
A total of 14 warnings in my pseries build are squashed.
--- arch/powerpc/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/uaccess.h +1 -1
@@ -274,7 +274,7 @@ do { \ ({ \ long __gu_err = -EFAULT; \ unsigned long __gu_val = 0; \ - __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ + const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ might_fault(); \ if (access_ok(VERIFY_READ, __gu_addr, (size))) \ __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
Signature · 1 line
2.9.3
PATCH 2/3 powerpc/sparse: constify the address pointer in __get_user_nocheck
In reply to Daniel AxtensIn __get_user_nocheck, we create an intermediate pointer for the user address we're about to fetch. We currently don't tag this pointer as const. Make it const, as we are simply dereferencing it, and it's scope is limited to the __get_user_nocheck macro.
---
This squashes 52 sparse warnings in my pseries build. They're similar to the ones squashed in the previous patch.
--- arch/powerpc/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/uaccess.h +1 -1
@@ -261,7 +261,7 @@ do { \ ({ \ long __gu_err; \ unsigned long __gu_val; \ - __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ + const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ __chk_user_ptr(ptr); \ if (!is_kernel_addr((unsigned long)__gu_addr)) \ might_fault(); \
Signature · 1 line
2.9.3
PATCH 3/3 powerpc/sparse: constify the address pointer in __get_user_nosleep
In reply to Daniel AxtensIn __get_user_nosleep, we create an intermediate pointer for the user address we're about to fetch. We currently don't tag this pointer as const. Make it const, as we are simply dereferencing it, and it's scope is limited to the __get_user_nosleep macro.
---
This is sparse neutral:
-arch/powerpc/kernel/hw_breakpoint.c:XX:14: warning: incorrect type in initializer (different address spaces)
- expected unsigned int [noderef] <asn:1>*__gu_addr
- got unsigned int *<noident>
+arch/powerpc/kernel/hw_breakpoint.c:XX:14: warning: incorrect type in initializer (different address spaces)
+ expected unsigned int const [noderef] <asn:1>*__gu_addr
+ got unsigned int *<noident>
It looks like a pointer not tagged with __user is being passed in. That will need to be fixed in a follow-up patch.
However this is still worth doing, as it makes the __get_user_* macros consistent.
--- arch/powerpc/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/uaccess.h +1 -1
@@ -286,7 +286,7 @@ do { \ ({ \ long __gu_err; \ unsigned long __gu_val; \ - __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ + const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ __chk_user_ptr(ptr); \ __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ (x) = (__force __typeof__(*(ptr)))__gu_val; \
Signature · 1 line
2.9.3
Re: [1/3] powerpc/sparse: constify the address pointer in __get_user_check
In reply to Daniel AxtensQuoted 6 lines · Daniel Axtens
In
__get_user_check, we create an intermediate pointer for the user address we're about to fetch. We currently don't tag this pointer as const. Make it const, as we are simply dereferencing it, and it's scope is limited to the__get_user_checkmacro.Signed-off-by Daniel Axtens <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/f84ed59a612d866cde0bd17ad2a52a
cheers