Fix riscv sparse warnings
Subsystems (2)
cover Fix riscv sparse warnings
This series simply fixes 2 recently introduced sparse warnings.
---
Alexandre Ghiti (2):
riscv: Fix sparse warning in __get_user_error()
riscv: Fix sparse warning about different address spaces
arch/riscv/include/asm/uaccess.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
---
base-commit: ae9a687664d965b13eeab276111b2f97dd02e090
change-id: 20250903-dev-alex-sparse_warnings_v1-ecb4a333afdd
Best regards,
Signature · 1 line
Alexandre Ghiti <[email protected]>
PATCH 1/2 riscv: Fix sparse warning in __get_user_error()
We used to assign 0 to x without an appropriate cast which results in sparse complaining when x is a pointer:
Quoted 1 line
Quoted 1 line
block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointer
So fix this by casting 0 to the correct type of x.
--- arch/riscv/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +1 -1
@@ -209,7 +209,7 @@ do { \ err =0 ; \break ; \ __gu_failed: \ - x =0 ; \ + x = (__typeof__ (x ))0 ; \ err = -EFAULT ; \ }while (0 )
Signature · 1 line
2.34.1
Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
These two are on me. Sorry.
Thanks for fixing them Alexandre.
Quoted 5 lines · Alexandre Ghiti
We used to assign 0 to x without an appropriate cast which results in sparse complaining when x is a pointer:
Quoted 1 line
Quoted 1 line
block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointer
Quoted 7 lines
So fix this by casting 0 to the correct type of x.
Reported-by kernel test robot <[email protected]>Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")Signed-off-by Alexandre Ghiti <[email protected]>
Quoted 18 lines
--- arch/riscv/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/include/asm/uaccess.h +1
-1@@ -209,7 +209,7 @@ do { \ err =0 ; \break ; \ __gu_failed: \ - x =0 ; \ + x = (__typeof__ (x ))0 ; \ err = -EFAULT ; \ }while (0 )
Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
In reply to Alexandre GhitiQuoted 22 lines · Alexandre Ghiti
We used to assign 0 to x without an appropriate cast which results in sparse complaining when x is a pointer:
Quoted 1 line
Quoted 1 line
block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointerSo fix this by casting 0 to the correct type of x.
Reported-by kernel test robot <[email protected]>Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/include/asm/uaccess.h +0
-0
arch/riscv/include/asm/uaccess.h do { \ · line 215
Quoted 8 lines
arch/riscv/include/asm/uaccess.h +1
-1@@ -209,7 +209,7 @@ do { \ err =0 ; \break ; \ __gu_failed: \ - x =0 ; \ + x = (__typeof__ (x ))0 ; \ err = -EFAULT ; \ }while (0 )
Hi Alex,
I applied that and checked that the sparse warnings were fixed as well, looks good to me.
Thanks,
Clément
Paul Walmsley
maintainerRe: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
In reply to Alexandre GhitiQuoted 6 lines · Alexandre Ghiti
We used to assign 0 to x without an appropriate cast which results in sparse complaining when x is a pointer:
Quoted 1 line
Quoted 1 line
block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointerSo fix this by casting 0 to the correct type of x.
Thanks, queued for v6.17-rc fixes.
- Paul
Paul Walmsley
maintainerRe: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
In reply to Alexandre GhitiQuoted 7 lines · Alexandre Ghiti
We used to assign 0 to x without an appropriate cast which results in sparse complaining when x is a pointer:
Quoted 1 line
Quoted 1 line
block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointerSo fix this by casting 0 to the correct type of x.
Quoted 8 lines
Reported-by kernel test robot <[email protected]>Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks, this one was sent upstream as part of the last fixes PR.
- Paul
PATCH 2/2 riscv: Fix sparse warning about different address spaces
In reply to Alexandre GhitiWe did not propagate the __user attribute of the pointers in __get_kernel_nofault() and __put_kernel_nofault(), which results in sparse complaining:
Quoted 1 line
Quoted 1 line
mm/maccess.c:41:17: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef]__user*from @@ got unsigned long long [usertype] * @@
mm/maccess.c:41:17: sparse: expected void const [noderef] __user *from
mm/maccess.c:41:17: sparse: got unsigned long long [usertype] *
So fix this by correctly casting those pointers.
--- arch/riscv/include/asm/uaccess.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/uaccess.h +2 -2
@@ -438,10 +438,10 @@ unsigned long __must_check clear_user(void __user *to, unsigned long n) }#define __get_kernel_nofault (dst, src, type, err_label) \ - __get_user_nocheck(*((type *)(dst)), (type *)(src), err_label) + __get_user_nocheck(*((type *)(dst)), (__force __user type *)(src), err_label)#define __put_kernel_nofault (dst, src, type, err_label) \ - __put_user_nocheck(*((type *)(src)), (type *)(dst), err_label) + __put_user_nocheck(*((type *)(src)), (__force __user type *)(dst), err_label) static __must_check __always_inline bool user_access_begin(const void __user *ptr, size_t len) {
Signature · 1 line
2.34.1
Re: [PATCH 2/2] riscv: Fix sparse warning about different address spaces
Quoted 8 lines · Alexandre Ghiti
We did not propagate the
__userattribute of the pointers in__get_kernel_nofault()and__put_kernel_nofault(), which results in sparse complaining:Quoted 1 line
Quoted 1 line
mm/maccess.c:41:17: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef]__user*from @@ got unsigned long long [usertype] * @@
mm/maccess.c:41:17: sparse: expected void const [noderef]__user*from
mm/maccess.c:41:17: sparse: got unsigned long long [usertype] *
Quoted 8 lines
So fix this by correctly casting those pointers.
Reported-by kernel test robot <[email protected]>Suggested-by Al Viro <[email protected]>Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")Signed-off-by Alexandre Ghiti <[email protected]>
Quoted 22 lines
--- arch/riscv/include/asm/uaccess.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/include/asm/uaccess.h +2
-2@@ -438,10 +438,10 @@ unsigned long __must_check clear_user(void __user *to, unsigned long n) }#define __get_kernel_nofault (dst, src, type, err_label) \ - __get_user_nocheck(*((type *)(dst)), (type *)(src), err_label) + __get_user_nocheck(*((type *)(dst)), (__force __user type *)(src), err_label)#define __put_kernel_nofault (dst, src, type, err_label) \ - __put_user_nocheck(*((type *)(src)), (type *)(dst), err_label) + __put_user_nocheck(*((type *)(src)), (__force __user type *)(dst), err_label) static __must_check __always_inline bool user_access_begin(const void __user *ptr, size_t len) {
Re: [PATCH 2/2] riscv: Fix sparse warning about different address spaces
In reply to Alexandre GhitiQuoted 28 lines · Alexandre Ghiti
We did not propagate the
__userattribute of the pointers in__get_kernel_nofault()and__put_kernel_nofault(), which results in sparse complaining:Quoted 1 line
Quoted 1 line
mm/maccess.c:41:17: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef]__user*from @@ got unsigned long long [usertype] * @@
mm/maccess.c:41:17: sparse: expected void const [noderef]__user*from
mm/maccess.c:41:17: sparse: got unsigned long long [usertype] *So fix this by correctly casting those pointers.
Reported-by kernel test robot <[email protected]>Suggested-by Al Viro <[email protected]>Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/uaccess.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/include/asm/uaccess.h +0
-0@@ -438,10 +438,10 @@ unsigned long __must_check clear_user(void __user *to, unsigned long n) }
arch/riscv/include/asm/uaccess.h unsigned long __must_check clear_user(void __user *to, unsigned long n) · line 447
Quoted 10 lines
arch/riscv/include/asm/uaccess.h +2
-2#define __get_kernel_nofault (dst, src, type, err_label) \ - __get_user_nocheck(*((type *)(dst)), (type *)(src), err_label) + __get_user_nocheck(*((type *)(dst)), (__force __user type *)(src), err_label)#define __put_kernel_nofault (dst, src, type, err_label) \ - __put_user_nocheck(*((type *)(src)), (type *)(dst), err_label) + __put_user_nocheck(*((type *)(src)), (__force __user type *)(dst), err_label) static __must_check __always_inline bool user_access_begin(const void __user *ptr, size_t len) {
Hi Alex,
LGTM,
Thanks,
Clément
Paul Walmsley
maintainerRe: [PATCH 2/2] riscv: Fix sparse warning about different address spaces
In reply to Alexandre GhitiQuoted 8 lines · Alexandre Ghiti
We did not propagate the
__userattribute of the pointers in__get_kernel_nofault()and__put_kernel_nofault(), which results in sparse complaining:Quoted 1 line
Quoted 1 line
mm/maccess.c:41:17: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef]__user*from @@ got unsigned long long [usertype] * @@
mm/maccess.c:41:17: sparse: expected void const [noderef]__user*from
mm/maccess.c:41:17: sparse: got unsigned long long [usertype] *
Quoted 8 lines
So fix this by correctly casting those pointers.
Reported-by kernel test robot <[email protected]>Suggested-by Al Viro <[email protected]>Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")Signed-off-by Alexandre Ghiti <[email protected]>
Thanks, queued for v6.17-rc fixes.
- Paul
Paul Walmsley
maintainerRe: [PATCH 2/2] riscv: Fix sparse warning about different address spaces
In reply to Alexandre GhitiQuoted 8 lines · Alexandre Ghiti
We did not propagate the
__userattribute of the pointers in__get_kernel_nofault()and__put_kernel_nofault(), which results in sparse complaining:Quoted 1 line
Quoted 1 line
mm/maccess.c:41:17: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef]__user*from @@ got unsigned long long [usertype] * @@
mm/maccess.c:41:17: sparse: expected void const [noderef]__user*from
mm/maccess.c:41:17: sparse: got unsigned long long [usertype] *
Quoted 8 lines
So fix this by correctly casting those pointers.
Reported-by kernel test robot <[email protected]>Suggested-by Al Viro <[email protected]>Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")Signed-off-by Alexandre Ghiti <[email protected]>
Thanks, this one was sent upstream as part of the last fixes PR.
- Paul
This series was applied to riscv/linux.git (for-next) by Paul Walmsley <[email protected]>:
Hello:
This series was applied to riscv/linux.git (for-next) by Paul Walmsley <[email protected]>:
Quoted 9 lines · On Wed, 03 Sep 2025 18:53:07 +0000 you wrote:
This series simply fixes 2 recently introduced sparse warnings.
Signed-off-by Alexandre Ghiti <[email protected]>---
Alexandre Ghiti (2):
riscv: Fix sparse warning in__get_user_error()
riscv: Fix sparse warning about different address spaces[...]
Here is the summary with links:
- [1/2] riscv: Fix sparse warning in __get_user_error()
https://git.kernel.org/riscv/c/fef7ded169ed - [2/2] riscv: Fix sparse warning about different address spaces https://git.kernel.org/riscv/c/a03ee11b8f85
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html