Skip to contentSkip to conversation

powerpc/sparse: constify addresses in get_user macros

PATCH In review Daniel Axtens 2 participants 5 messages Jan 30, 2017 – Feb 2, 2017 PowerPC

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index a15d84d59356..71d81cbe3781 100644
@@ -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
#3 lore raw

PATCH 2/3 powerpc/sparse: constify the address pointer in __get_user_nocheck

In reply to Daniel Axtens

In __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
index 71d81cbe3781..44ded4193001 100644
@@ -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
#4 lore raw

PATCH 3/3 powerpc/sparse: constify the address pointer in __get_user_nosleep

In reply to Daniel Axtens

In __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
index 44ded4193001..0e6add3187bc 100644
@@ -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
#2 lore raw

Re: [1/3] powerpc/sparse: constify the address pointer in __get_user_check

In reply to Daniel Axtens
Quoted 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_check macro.

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f84ed59a612d866cde0bd17ad2a52a

cheers