Skip to contentSkip to conversation

riscv: uaccess: fix type of 0 variable on error in get_user()

PATCH Applied Ben Dooks 5 participants 5 messages Dec 29, 2022 – Jan 5, 2023 RISC-V

lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH 1/1 riscv: uaccess: fix type of 0 variable on error in get_user()

If the get_user(x, ptr) has x as a pointer, then the setting of (x) = 0 is going to produce the following sparse warning, so fix this by forcing the type of 'x' when access_ok() fails.

fs/aio.c:2073:21: warning: Using plain integer as NULL pointer

---
 arch/riscv/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +1 -1
index 855450bed9f5..ec0cab9fbddd 100644
@@ -165,7 +165,7 @@ do {								\
 	might_fault();						\
 	access_ok(__p, sizeof(*__p)) ?		\
 		__get_user((x), __p) :				\
-		((x) = 0, -EFAULT);				\
+		((x) = (__force __typeof__(x))0, -EFAULT);	\
 })
 
 #define __put_user_asm(insn, x, ptr, err)			\
Signature · 7 lines
2.39.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · On Thu, 29 Dec 2022 09:05:45 PST (-0800), [email protected] wrote:

If the get_user(x, ptr) has x as a pointer, then the setting of (x) = 0 is going to produce the following sparse warning, so fix this by forcing the type of 'x' when access_ok() fails.

fs/aio.c:2073:21: warning: Using plain integer as NULL pointer

---
 arch/riscv/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +0 -0
index 855450bed9f5..ec0cab9fbddd 100644

arch/riscv/include/asm/uaccess.h do { \ · line 171

Quoted 8 lines
arch/riscv/include/asm/uaccess.h +1 -1
@@ -165,7 +165,7 @@ do {								\
 	might_fault();						\
 	access_ok(__p, sizeof(*__p)) ?		\
 		__get_user((x), __p) :				\
-		((x) = 0, -EFAULT);				\
+		((x) = (__force __typeof__(x))0, -EFAULT);	\
 })
 
 #define __put_user_asm(insn, x, ptr, err)			\

Looks like arm64 has a pretty similar pattern. They've got the __force __typeof__ already, but given the similarity it might be worth refactoring these to share the error checking code.

I'll give this a bit of time like usual, unless anyone's opposed I'll put it on fixes. I wasn't planning on sending a PR this week anyway due to the holidays.

Thanks!

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 24 lines · Palmer Dabbelt
Quoted 23 lines · On Thu, 29 Dec 2022 09:05:45 PST (-0800), [email protected] wrote:

If the get_user(x, ptr) has x as a pointer, then the setting of (x) = 0 is going to produce the following sparse warning, so fix this by forcing the type of 'x' when access_ok() fails.

fs/aio.c:2073:21: warning: Using plain integer as NULL pointer

---
 arch/riscv/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/uaccess.h +1 -1
index 855450bed9f5..ec0cab9fbddd 100644
@@ -165,7 +165,7 @@ do {								\
 	might_fault();						\
 	access_ok(__p, sizeof(*__p)) ?		\
 		__get_user((x), __p) :				\
-		((x) = 0, -EFAULT);				\
+		((x) = (__force __typeof__(x))0, -EFAULT);	\
 })
 
Quoted 5 lines

arch/riscv/include/asm/uaccess.h do { \ · line 171

Quoted 1 line
arch/riscv/include/asm/uaccess.h +0 -0
 #define __put_user_asm(insn, x, ptr, err)			\

Looks like arm64 has a pretty similar pattern. They've got the __force __typeof__ already, but given the similarity it might be worth refactoring these to share the error checking code.

I looked there for an idea on how to fix.

Quoted 5 lines

I'll give this a bit of time like usual, unless anyone's opposed I'll put it on fixes. I wasn't planning on sending a PR this week anyway due to the holidays.

Ok, it's a warning which would be nice to be fixed.

Signature · 9 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw
In reply to Ben Dooks
Quoted 8 lines · Ben Dooks

If the get_user(x, ptr) has x as a pointer, then the setting of (x) = 0 is going to produce the following sparse warning, so fix this by forcing the type of 'x' when access_ok() fails.

fs/aio.c:2073:21: warning: Using plain integer as NULL pointer

[...]

Applied, thanks!

[1/1] riscv: uaccess: fix type of 0 variable on error in get_user()

      https://git.kernel.org/palmer/c/b9b916aee671

Best regards,

Signature · 1 line
Palmer Dabbelt <[email protected]>
#4 lore raw
In reply to Ben Dooks
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:

Quoted 9 lines · On Thu, 29 Dec 2022 17:05:45 +0000 you wrote:

If the get_user(x, ptr) has x as a pointer, then the setting of (x) = 0 is going to produce the following sparse warning, so fix this by forcing the type of 'x' when access_ok() fails.

fs/aio.c:2073:21: warning: Using plain integer as NULL pointer

[...]

Here is the summary with links:
- riscv: uaccess: fix type of 0 variable on error in get_user()

    https://git.kernel.org/riscv/c/b9b916aee671

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html