Skip to content

Commit ae6b019

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/uaccess: Add missing __force to casts in __access_ok() and valid_user_address()
Sparse complains about losing the __user address space due to the cast to long: uaccess_64.h:88:24: sparse: warning: cast removes address space '__user' of expression Annotate it with __force to tell sparse that this is intentional. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20240304005104.677606054@linutronix.de
1 parent 71eb489 commit ae6b019

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/x86/include/asm/uaccess_64.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static inline unsigned long __untagged_addr_remote(struct mm_struct *mm,
5454
* half and a user half. When cast to a signed type, user pointers
5555
* are positive and kernel pointers are negative.
5656
*/
57-
#define valid_user_address(x) ((long)(x) >= 0)
57+
#define valid_user_address(x) ((__force long)(x) >= 0)
5858

5959
/*
6060
* User pointers can have tag bits on x86-64. This scheme tolerates
@@ -87,8 +87,9 @@ static inline bool __access_ok(const void __user *ptr, unsigned long size)
8787
if (__builtin_constant_p(size <= PAGE_SIZE) && size <= PAGE_SIZE) {
8888
return valid_user_address(ptr);
8989
} else {
90-
unsigned long sum = size + (unsigned long)ptr;
91-
return valid_user_address(sum) && sum >= (unsigned long)ptr;
90+
unsigned long sum = size + (__force unsigned long)ptr;
91+
92+
return valid_user_address(sum) && sum >= (__force unsigned long)ptr;
9293
}
9394
}
9495
#define __access_ok __access_ok

0 commit comments

Comments
 (0)