[PATCH] riscv: uaccess: fix sparse warning about cast to restricted type

Ben Dooks ben.dooks at codethink.co.uk
Wed Mar 11 03:51:47 PDT 2026


It seems recent changes have made sparse warning about casting to
restricted types whe using __get_user() in drivers such as the
drivers/pci/proc.c.

Fix this with a __force to fix such warnings as:

drivers/pci/proc.c:148:17: warning: cast to restricted __le16
drivers/pci/proc.c:148:17: warning: cast to restricted __le16
drivers/pci/proc.c:148:17: warning: cast to restricted __le16
drivers/pci/proc.c:148:17: warning: cast to restricted __le16
drivers/pci/proc.c:157:17: warning: cast to restricted __le32
drivers/pci/proc.c:157:17: warning: cast to restricted __le32
drivers/pci/proc.c:157:17: warning: cast to restricted __le32
drivers/pci/proc.c:157:17: warning: cast to restricted __le32
drivers/pci/proc.c:166:17: warning: cast to restricted __le16
drivers/pci/proc.c:166:17: warning: cast to restricted __le16
drivers/pci/proc.c:166:17: warning: cast to restricted __le16
drivers/pci/proc.c:166:17: warning: cast to restricted __le16

Signed-off-by: Ben Dooks <ben.dooks at codethink.co.uk>
---
 arch/riscv/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h
index 11c9886c3b70..5d4ec15584cf 100644
--- a/arch/riscv/include/asm/uaccess.h
+++ b/arch/riscv/include/asm/uaccess.h
@@ -112,7 +112,7 @@ do {								\
 		_ASM_EXTABLE_UACCESS_ERR(1b, %l2, %0)		\
 		: "=&r" (__tmp)					\
 		: "m" (*(ptr)) : : label);			\
-	(x) = (__typeof__(x))(unsigned long)__tmp;		\
+	(x) = (__force __typeof__(x))(unsigned long)__tmp;	\
 } while (0)
 #else /* !CONFIG_CC_HAS_ASM_GOTO_OUTPUT */
 #define __get_user_asm(insn, x, ptr, label)			\
-- 
2.37.2.352.g3c44437643




More information about the linux-riscv mailing list