Skip to contentSkip to conversation

asm-generic: Force cast get_user() setting x to 0

PATCH In review Stephen Boyd 2 participants 3 messages Feb 17, 2017 – Feb 27, 2017 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 asm-generic: Force cast get_user() setting x to 0

If we call get_user() with an __le* or __be* type sparse will complain when we assign the result to 0 on the faulting path. Let's force cast here so that sparse doesn't complain. This mirrors what we do in __get_user() as well.

---

I made a similar fix to arm64 headers, and it looks like asm-generic would need the same fix.

 include/asm-generic/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/uaccess.h +1 -1
index cc6bb319e464..6352d61df7eb 100644
@@ -227,7 +227,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
 	might_fault();						\
 	access_ok(VERIFY_READ, __p, sizeof(*ptr)) ?		\
 		__get_user((x), (__typeof__(*(ptr)) *)__p) :	\
-		((x) = (__typeof__(*(ptr)))0,-EFAULT);		\
+		((x) = (__force __typeof__(*(ptr)))0, -EFAULT);	\
 })
 
 #ifndef __get_user_fn
Signature · 1 line
2.10.0.297.gf6727b0
#1 lore raw

Quoting Stephen Boyd (2017-02-17 08:52:29)

Quoted 10 lines

If we call get_user() with an __le* or __be* type sparse will complain when we assign the result to 0 on the faulting path. Let's force cast here so that sparse doesn't complain. This mirrors what we do in __get_user() as well.

---

I made a similar fix to arm64 headers, and it looks like asm-generic would need the same fix.

I suppose we can ignore this. I was using sparse v0.5.0 but it seems that later versions of sparse don't complain here anymore as Luc has pointed out.

-Stephen

Quoted 17 lines
 include/asm-generic/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/uaccess.h +1 -1
index cc6bb319e464..6352d61df7eb 100644
@@ -227,7 +227,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
        might_fault();                                          \
        access_ok(VERIFY_READ, __p, sizeof(*ptr)) ?             \
                __get_user((x), (__typeof__(*(ptr)) *)__p) :    \
-               ((x) = (__typeof__(*(ptr)))0,-EFAULT);          \
+               ((x) = (__force __typeof__(*(ptr)))0, -EFAULT); \
 })
 
 #ifndef __get_user_fn
maintainer
#2 lore raw
Quoted 9 lines · Stephen Boyd

Quoting Stephen Boyd (2017-02-17 08:52:29)

Quoted 8 lines

If we call get_user() with an __le* or __be* type sparse will complain when we assign the result to 0 on the faulting path. Let's force cast here so that sparse doesn't complain. This mirrors what we do in __get_user() as well.

---

Quoted 6 lines
Quoted 2 lines

I made a similar fix to arm64 headers, and it looks like asm-generic would need the same fix.

I suppose we can ignore this. I was using sparse v0.5.0 but it seems that later versions of sparse don't complain here anymore as Luc has pointed out.

Ok, thanks for the follow-up.

Arnd