summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorZong Li <zong@andestech.com>2018-08-13 16:02:53 +0800
committerGreentime Hu <greentime@andestech.com>2018-09-04 14:45:17 +0800
commit487913ab18c215b06611c4c91c7e905fc0960eb8 (patch)
treee03efb3ed02809614c82d6ce7dee734db3ee24d5 /arch
parent7ef39548df8cdb6406e3b4b7255e7f8cd3fe3b13 (diff)
nds32: Extract the checking and getting pointer to a macro
Signed-off-by: Zong Li <zong@andestech.com> Acked-by: Greentime Hu <greentime@andestech.com> Signed-off-by: Greentime Hu <greentime@andestech.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/nds32/include/asm/uaccess.h80
1 files changed, 41 insertions, 39 deletions
diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uaccess.h
index e1a2b5b749b9..362a32d9bd16 100644
--- a/arch/nds32/include/asm/uaccess.h
+++ b/arch/nds32/include/asm/uaccess.h
@@ -75,54 +75,54 @@ static inline void set_fs(mm_segment_t fs)
* versions are void (ie, don't return a value as such).
*/
-#define get_user(x, ptr) \
-({ \
- long __e = -EFAULT; \
- const __typeof__(*(ptr)) __user *__p = (ptr); \
- if (likely(access_ok(VERIFY_READ, __p, sizeof(*__p)))) { \
- __e = __get_user(x, __p); \
- } else { \
- (x) = 0; \
- } \
- __e; \
-})
+#define get_user __get_user \
#define __get_user(x, ptr) \
({ \
long __gu_err = 0; \
- __get_user_err((x), (ptr), __gu_err); \
+ __get_user_check((x), (ptr), __gu_err); \
__gu_err; \
})
#define __get_user_error(x, ptr, err) \
({ \
- __get_user_err((x), (ptr), err); \
+ __get_user_check((x), (ptr), (err)); \
(void)0; \
})
+#define __get_user_check(x, ptr, err) \
+({ \
+ const __typeof__(*(ptr)) __user *__p = (ptr); \
+ might_fault(); \
+ if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \
+ __get_user_err((x), __p, (err)); \
+ } else { \
+ (x) = 0; (err) = -EFAULT; \
+ } \
+})
+
#define __get_user_err(x, ptr, err) \
do { \
- const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
unsigned long __gu_val; \
- __chk_user_ptr(__gu_addr); \
- switch (sizeof(*(__gu_addr))) { \
+ __chk_user_ptr(ptr); \
+ switch (sizeof(*(ptr))) { \
case 1: \
- __get_user_asm("lbi", __gu_val, __gu_addr, (err)); \
+ __get_user_asm("lbi", __gu_val, (ptr), (err)); \
break; \
case 2: \
- __get_user_asm("lhi", __gu_val, __gu_addr, (err)); \
+ __get_user_asm("lhi", __gu_val, (ptr), (err)); \
break; \
case 4: \
- __get_user_asm("lwi", __gu_val, __gu_addr, (err)); \
+ __get_user_asm("lwi", __gu_val, (ptr), (err)); \
break; \
case 8: \
- __get_user_asm_dword(__gu_val, __gu_addr, (err)); \
+ __get_user_asm_dword(__gu_val, (ptr), (err)); \
break; \
default: \
BUILD_BUG(); \
break; \
} \
- (x) = (__typeof__(*(__gu_addr)))__gu_val; \
+ (x) = (__force __typeof__(*(ptr)))__gu_val; \
} while (0)
#define __get_user_asm(inst, x, addr, err) \
@@ -170,15 +170,7 @@ do { \
: "r"(addr), "i"(-EFAULT) \
: "cc")
-#define put_user(x, ptr) \
-({ \
- long __e = -EFAULT; \
- __typeof__(*(ptr)) __user *__p = (ptr); \
- if (likely(access_ok(VERIFY_WRITE, __p, sizeof(*__p)))) { \
- __e = __put_user(x, __p); \
- } \
- __e; \
-})
+#define put_user __put_user \
#define __put_user(x, ptr) \
({ \
@@ -189,27 +181,37 @@ do { \
#define __put_user_error(x, ptr, err) \
({ \
- __put_user_err((x), (ptr), err); \
+ __put_user_err((x), (ptr), (err)); \
(void)0; \
})
+#define __put_user_check(x, ptr, err) \
+({ \
+ __typeof__(*(ptr)) __user *__p = (ptr); \
+ might_fault(); \
+ if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \
+ __put_user_err((x), __p, (err)); \
+ } else { \
+ (err) = -EFAULT; \
+ } \
+})
+
#define __put_user_err(x, ptr, err) \
do { \
- __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
- __typeof__(*(__pu_addr)) __pu_val = (x); \
- __chk_user_ptr(__pu_addr); \
- switch (sizeof(*(__pu_addr))) { \
+ __typeof__(*(ptr)) __pu_val = (x); \
+ __chk_user_ptr(ptr); \
+ switch (sizeof(*(ptr))) { \
case 1: \
- __put_user_asm("sbi", __pu_val, __pu_addr, (err)); \
+ __put_user_asm("sbi", __pu_val, (ptr), (err)); \
break; \
case 2: \
- __put_user_asm("shi", __pu_val, __pu_addr, (err)); \
+ __put_user_asm("shi", __pu_val, (ptr), (err)); \
break; \
case 4: \
- __put_user_asm("swi", __pu_val, __pu_addr, (err)); \
+ __put_user_asm("swi", __pu_val, (ptr), (err)); \
break; \
case 8: \
- __put_user_asm_dword(__pu_val, __pu_addr, (err)); \
+ __put_user_asm_dword(__pu_val, (ptr), (err)); \
break; \
default: \
BUILD_BUG(); \