Skip to contentSkip to conversation

Fix riscv sparse warnings

PATCH Applied Alexandre Ghiti 5 participants 12 messages Sep 3, 2025 – Sep 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
---
 arch/riscv/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +1 -1
index 22e3f52a763d1c0350e8185225e4c99aac3fc549..551e7490737effb2c238e6a4db50293ece7c9df9 100644
@@ -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
Reviewed-by on v1 1/2
#2 lore raw

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.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
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
index 22e3f52a763d1c0350e8185225e4c99aac3fc549..551e7490737effb2c238e6a4db50293ece7c9df9 100644
@@ -209,7 +209,7 @@ do {									\
  		err = 0;						\
  		break;							\
  __gu_failed:								\
-		x = 0;							\
+		x = (__typeof__(x))0;					\
  		err = -EFAULT;						\
  } while (0)
 
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()

In reply to Alexandre Ghiti
Quoted 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 pointer

So fix this by casting 0 to the correct type of x.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
---
 arch/riscv/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +0 -0
index 22e3f52a763d1c0350e8185225e4c99aac3fc549..551e7490737effb2c238e6a4db50293ece7c9df9 100644

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

maintainer
#4 lore raw

Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()

In reply to Alexandre Ghiti
Quoted 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 pointer

So fix this by casting 0 to the correct type of x.

Thanks, queued for v6.17-rc fixes.

- Paul

maintainer
#5 lore raw

Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()

In reply to Alexandre Ghiti
Quoted 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 pointer

So fix this by casting 0 to the correct type of x.

Quoted 8 lines
Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
---
 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

#6 lore raw

PATCH 2/2 riscv: Fix sparse warning about different address spaces

In reply to Alexandre Ghiti

We 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.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
---
 arch/riscv/include/asm/uaccess.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/uaccess.h +2 -2
index 551e7490737effb2c238e6a4db50293ece7c9df9..f5f4f7f85543f2a635b18e4bd1c6202b20e3b239 100644
@@ -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
Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] riscv: Fix sparse warning about different address spaces

Quoted 8 lines · Alexandre Ghiti

We 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] *

Quoted 8 lines

So fix this by correctly casting those pointers.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
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
index 551e7490737effb2c238e6a4db50293ece7c9df9..f5f4f7f85543f2a635b18e4bd1c6202b20e3b239 100644
@@ -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)
  {
Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] riscv: Fix sparse warning about different address spaces

In reply to Alexandre Ghiti
Quoted 28 lines · Alexandre Ghiti

We 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.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
---
 arch/riscv/include/asm/uaccess.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/uaccess.h +0 -0
index 551e7490737effb2c238e6a4db50293ece7c9df9..f5f4f7f85543f2a635b18e4bd1c6202b20e3b239 100644
@@ -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

maintainer
#9 lore raw

Re: [PATCH 2/2] riscv: Fix sparse warning about different address spaces

In reply to Alexandre Ghiti
Quoted 8 lines · Alexandre Ghiti

We 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] *

Quoted 8 lines

So fix this by correctly casting those pointers.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")

Thanks, queued for v6.17-rc fixes.

- Paul

maintainer
#10 lore raw

Re: [PATCH 2/2] riscv: Fix sparse warning about different address spaces

In reply to Alexandre Ghiti
Quoted 8 lines · Alexandre Ghiti

We 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] *

Quoted 8 lines

So fix this by correctly casting those pointers.

Fixes f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")

Thanks, this one was sent upstream as part of the last fixes PR.

- Paul

#11 lore raw
In reply to Alexandre Ghiti
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.

---
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