linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix get_user and put_user pointer issue
@ 2018-08-13  9:26 Zong Li
  2018-08-13  9:26 ` [PATCH 1/3] nds32: Fix get_user/put_user macro expand pointer problem Zong Li
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Zong Li @ 2018-08-13  9:26 UTC (permalink / raw)
  To: green.hu, deanbo422, linux-kernel; +Cc: zongbox, Zong Li

These patches fix the issue of expand macro with pointer argument,
clean up the coding style and refactor the macro by extracting the
checking and getting pointer to another macro definition.


Zong Li (3):
  nds32: Fix get_user/put_user macro expand pointer problem
  nds32: Clean up the coding style
  nds32: Extract the checking and getting pointer to a macro

 arch/nds32/include/asm/uaccess.h | 229 ++++++++++++++++++++-------------------
 1 file changed, 119 insertions(+), 110 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] nds32: Fix get_user/put_user macro expand pointer problem
  2018-08-13  9:26 [PATCH 0/3] Fix get_user and put_user pointer issue Zong Li
@ 2018-08-13  9:26 ` Zong Li
  2018-08-13  9:26 ` [PATCH 2/3] nds32: Clean up the coding style Zong Li
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Zong Li @ 2018-08-13  9:26 UTC (permalink / raw)
  To: green.hu, deanbo422, linux-kernel; +Cc: zongbox, Zong Li

The pointer argument of macro need to be taken out once first, and then
use the new pointer in the macro body.

In kernel/trace/trace.c, get_user(ch, ubuf++) causes the unexpected
increment after expand the macro.

Signed-off-by: Zong Li <zong@andestech.com>
---
 arch/nds32/include/asm/uaccess.h | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uaccess.h
index 18a009f..3f771e0 100644
--- a/arch/nds32/include/asm/uaccess.h
+++ b/arch/nds32/include/asm/uaccess.h
@@ -78,8 +78,9 @@ static inline void set_fs(mm_segment_t fs)
 #define get_user(x,p)							\
 ({									\
 	long __e = -EFAULT;						\
-	if(likely(access_ok(VERIFY_READ,  p, sizeof(*p)))) {		\
-		__e = __get_user(x,p);					\
+	const __typeof__(*(p)) __user *__p = (p);			\
+	if(likely(access_ok(VERIFY_READ, __p, sizeof(*__p)))) {		\
+		__e = __get_user(x, __p);				\
 	} else								\
 		x = 0;							\
 	__e;								\
@@ -99,10 +100,10 @@ static inline void set_fs(mm_segment_t fs)
 
 #define __get_user_err(x,ptr,err)					\
 do {									\
-	unsigned long __gu_addr = (unsigned long)(ptr);			\
+	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);		\
 	unsigned long __gu_val;						\
-	__chk_user_ptr(ptr);						\
-	switch (sizeof(*(ptr))) {					\
+	__chk_user_ptr(__gu_addr);					\
+	switch (sizeof(*(__gu_addr))) {					\
 	case 1:								\
 		__get_user_asm("lbi",__gu_val,__gu_addr,err);		\
 		break;							\
@@ -119,7 +120,7 @@ do {									\
 		BUILD_BUG(); 						\
 		break;							\
 	}								\
-	(x) = (__typeof__(*(ptr)))__gu_val;				\
+	(x) = (__typeof__(*(__gu_addr)))__gu_val;			\
 } while (0)
 
 #define __get_user_asm(inst,x,addr,err)					\
@@ -169,8 +170,9 @@ do {									\
 #define put_user(x,p)							\
 ({									\
 	long __e = -EFAULT;						\
-	if(likely(access_ok(VERIFY_WRITE,  p, sizeof(*p)))) {		\
-		__e = __put_user(x,p);					\
+	__typeof__(*(p)) __user *__p = (p);				\
+	if(likely(access_ok(VERIFY_WRITE, __p, sizeof(*__p)))) {	\
+		__e = __put_user(x, __p);				\
 	}								\
 	__e;								\
 })
@@ -189,10 +191,10 @@ do {									\
 
 #define __put_user_err(x,ptr,err)					\
 do {									\
-	unsigned long __pu_addr = (unsigned long)(ptr);			\
-	__typeof__(*(ptr)) __pu_val = (x);				\
-	__chk_user_ptr(ptr);						\
-	switch (sizeof(*(ptr))) {					\
+	__typeof__(*(ptr)) __user *__pu_addr = (ptr);			\
+	__typeof__(*(__pu_addr)) __pu_val = (x);			\
+	__chk_user_ptr(__pu_addr);					\
+	switch (sizeof(*(__pu_addr))) {					\
 	case 1:								\
 		__put_user_asm("sbi",__pu_val,__pu_addr,err);		\
 		break;							\
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] nds32: Clean up the coding style
  2018-08-13  9:26 [PATCH 0/3] Fix get_user and put_user pointer issue Zong Li
  2018-08-13  9:26 ` [PATCH 1/3] nds32: Fix get_user/put_user macro expand pointer problem Zong Li
@ 2018-08-13  9:26 ` Zong Li
  2018-08-13  9:26 ` [PATCH 3/3] nds32: Extract the checking and getting pointer to a macro Zong Li
  2018-08-21  7:03 ` [PATCH 0/3] Fix get_user and put_user pointer issue Greentime Hu
  3 siblings, 0 replies; 5+ messages in thread
From: Zong Li @ 2018-08-13  9:26 UTC (permalink / raw)
  To: green.hu, deanbo422, linux-kernel; +Cc: zongbox, Zong Li

1. Adjust indentation.
2. Unify argument name of each macro.
3. Add space after comma in parameters list.
4. Add space after 'if' keyword.
5. Replace space by tab.
6. Change asm volatile to __asm__ __volatile__

Signed-off-by: Zong Li <zong@andestech.com>
---
 arch/nds32/include/asm/uaccess.h | 201 ++++++++++++++++++++-------------------
 1 file changed, 103 insertions(+), 98 deletions(-)

diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uaccess.h
index 3f771e0..e1a2b5b 100644
--- a/arch/nds32/include/asm/uaccess.h
+++ b/arch/nds32/include/asm/uaccess.h
@@ -38,7 +38,7 @@ struct exception_table_entry {
 extern int fixup_exception(struct pt_regs *regs);
 
 #define KERNEL_DS 	((mm_segment_t) { ~0UL })
-#define USER_DS     	((mm_segment_t) {TASK_SIZE - 1})
+#define USER_DS		((mm_segment_t) {TASK_SIZE - 1})
 
 #define get_ds()	(KERNEL_DS)
 #define get_fs()	(current_thread_info()->addr_limit)
@@ -49,11 +49,11 @@ static inline void set_fs(mm_segment_t fs)
 	current_thread_info()->addr_limit = fs;
 }
 
-#define segment_eq(a, b)    ((a) == (b))
+#define segment_eq(a, b)	((a) == (b))
 
 #define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs() -size))
 
-#define access_ok(type, addr, size)                 \
+#define access_ok(type, addr, size)	\
 	__range_ok((unsigned long)addr, (unsigned long)size)
 /*
  * Single-value transfer routines.  They automatically use the right
@@ -75,46 +75,48 @@ static inline void set_fs(mm_segment_t fs)
  * versions are void (ie, don't return a value as such).
  */
 
-#define get_user(x,p)							\
+#define get_user(x, ptr)						\
 ({									\
 	long __e = -EFAULT;						\
-	const __typeof__(*(p)) __user *__p = (p);			\
-	if(likely(access_ok(VERIFY_READ, __p, sizeof(*__p)))) {		\
+	const __typeof__(*(ptr)) __user *__p = (ptr);			\
+	if (likely(access_ok(VERIFY_READ, __p, sizeof(*__p)))) {	\
 		__e = __get_user(x, __p);				\
-	} else								\
-		x = 0;							\
+	} else {							\
+		(x) = 0;						\
+	}								\
 	__e;								\
 })
-#define __get_user(x,ptr)						\
+
+#define __get_user(x, ptr)						\
 ({									\
 	long __gu_err = 0;						\
-	__get_user_err((x),(ptr),__gu_err);				\
+	__get_user_err((x), (ptr), __gu_err);				\
 	__gu_err;							\
 })
 
-#define __get_user_error(x,ptr,err)					\
+#define __get_user_error(x, ptr, err)					\
 ({									\
-	__get_user_err((x),(ptr),err);					\
-	(void) 0;							\
+	__get_user_err((x), (ptr), err);				\
+	(void)0;							\
 })
 
-#define __get_user_err(x,ptr,err)					\
+#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))) {					\
 	case 1:								\
-		__get_user_asm("lbi",__gu_val,__gu_addr,err);		\
+		__get_user_asm("lbi", __gu_val, __gu_addr, (err));	\
 		break;							\
 	case 2:								\
-		__get_user_asm("lhi",__gu_val,__gu_addr,err);		\
+		__get_user_asm("lhi", __gu_val, __gu_addr, (err));	\
 		break;							\
 	case 4:								\
-		__get_user_asm("lwi",__gu_val,__gu_addr,err);		\
+		__get_user_asm("lwi", __gu_val, __gu_addr, (err));	\
 		break;							\
 	case 8:								\
-		__get_user_asm_dword(__gu_val,__gu_addr,err);		\
+		__get_user_asm_dword(__gu_val, __gu_addr, (err));	\
 		break;							\
 	default:							\
 		BUILD_BUG(); 						\
@@ -123,23 +125,23 @@ do {									\
 	(x) = (__typeof__(*(__gu_addr)))__gu_val;			\
 } while (0)
 
-#define __get_user_asm(inst,x,addr,err)					\
-	asm volatile(							\
-	"1:	"inst"	%1,[%2]\n"					\
-	"2:\n"								\
-	"	.section .fixup,\"ax\"\n"				\
-	"	.align	2\n"						\
-	"3:	move %0, %3\n"						\
-	"	move %1, #0\n"						\
-	"	b	2b\n"						\
-	"	.previous\n"						\
-	"	.section __ex_table,\"a\"\n"				\
-	"	.align	3\n"						\
-	"	.long	1b, 3b\n"					\
-	"	.previous"						\
-	: "+r" (err), "=&r" (x)						\
-	: "r" (addr), "i" (-EFAULT)					\
-	: "cc")
+#define __get_user_asm(inst, x, addr, err)				\
+	__asm__ __volatile__ (						\
+		"1:	"inst"	%1,[%2]\n"				\
+		"2:\n"							\
+		"	.section .fixup,\"ax\"\n"			\
+		"	.align	2\n"					\
+		"3:	move %0, %3\n"					\
+		"	move %1, #0\n"					\
+		"	b	2b\n"					\
+		"	.previous\n"					\
+		"	.section __ex_table,\"a\"\n"			\
+		"	.align	3\n"					\
+		"	.long	1b, 3b\n"				\
+		"	.previous"					\
+		: "+r" (err), "=&r" (x)					\
+		: "r" (addr), "i" (-EFAULT)				\
+		: "cc")
 
 #ifdef __NDS32_EB__
 #define __gu_reg_oper0 "%H1"
@@ -150,62 +152,64 @@ do {									\
 #endif
 
 #define __get_user_asm_dword(x, addr, err) 				\
-	asm volatile(			    				\
-	"\n1:\tlwi " __gu_reg_oper0 ",[%2]\n"				\
-	"\n2:\tlwi " __gu_reg_oper1 ",[%2+4]\n"				\
-	"3:\n"								\
-	"	.section .fixup,\"ax\"\n"				\
-	"	.align	2\n"						\
-	"4:	move	%0, %3\n"					\
-	"	b	3b\n"						\
-	"	.previous\n"						\
-	"	.section __ex_table,\"a\"\n"				\
-	"	.align	3\n"						\
-	"	.long	1b, 4b\n"					\
-	"	.long	2b, 4b\n"					\
-	"	.previous"						\
-	: "+r"(err), "=&r"(x)                				\
-	: "r"(addr), "i"(-EFAULT) 					\
-	: "cc")
-#define put_user(x,p)							\
+	__asm__ __volatile__ (						\
+		"\n1:\tlwi " __gu_reg_oper0 ",[%2]\n"			\
+		"\n2:\tlwi " __gu_reg_oper1 ",[%2+4]\n"			\
+		"3:\n"							\
+		"	.section .fixup,\"ax\"\n"			\
+		"	.align	2\n"					\
+		"4:	move	%0, %3\n"				\
+		"	b	3b\n"					\
+		"	.previous\n"					\
+		"	.section __ex_table,\"a\"\n"			\
+		"	.align	3\n"					\
+		"	.long	1b, 4b\n"				\
+		"	.long	2b, 4b\n"				\
+		"	.previous"					\
+		: "+r"(err), "=&r"(x)					\
+		: "r"(addr), "i"(-EFAULT)				\
+		: "cc")
+
+#define put_user(x, ptr)						\
 ({									\
 	long __e = -EFAULT;						\
-	__typeof__(*(p)) __user *__p = (p);				\
-	if(likely(access_ok(VERIFY_WRITE, __p, sizeof(*__p)))) {	\
+	__typeof__(*(ptr)) __user *__p = (ptr);				\
+	if (likely(access_ok(VERIFY_WRITE, __p, sizeof(*__p)))) {	\
 		__e = __put_user(x, __p);				\
 	}								\
 	__e;								\
 })
-#define __put_user(x,ptr)						\
+
+#define __put_user(x, ptr)						\
 ({									\
 	long __pu_err = 0;						\
-	__put_user_err((x),(ptr),__pu_err);				\
+	__put_user_err((x), (ptr), __pu_err);				\
 	__pu_err;							\
 })
 
-#define __put_user_error(x,ptr,err)					\
+#define __put_user_error(x, ptr, err)					\
 ({									\
-	__put_user_err((x),(ptr),err);					\
-	(void) 0;							\
+	__put_user_err((x), (ptr), err);				\
+	(void)0;							\
 })
 
-#define __put_user_err(x,ptr,err)					\
+#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))) {					\
 	case 1:								\
-		__put_user_asm("sbi",__pu_val,__pu_addr,err);		\
+		__put_user_asm("sbi", __pu_val, __pu_addr, (err));	\
 		break;							\
 	case 2: 							\
-		__put_user_asm("shi",__pu_val,__pu_addr,err);		\
+		__put_user_asm("shi", __pu_val, __pu_addr, (err));	\
 		break;							\
 	case 4: 							\
-		__put_user_asm("swi",__pu_val,__pu_addr,err);		\
+		__put_user_asm("swi", __pu_val, __pu_addr, (err));	\
 		break;							\
 	case 8:								\
-		__put_user_asm_dword(__pu_val,__pu_addr,err);		\
+		__put_user_asm_dword(__pu_val, __pu_addr, (err));	\
 		break;							\
 	default:							\
 		BUILD_BUG(); 						\
@@ -213,22 +217,22 @@ do {									\
 	}								\
 } while (0)
 
-#define __put_user_asm(inst,x,addr,err)					\
-	asm volatile(							\
-	"1:	"inst"	%1,[%2]\n"					\
-	"2:\n"								\
-	"	.section .fixup,\"ax\"\n"				\
-	"	.align	2\n"						\
-	"3:	move	%0, %3\n"					\
-	"	b	2b\n"						\
-	"	.previous\n"						\
-	"	.section __ex_table,\"a\"\n"				\
-	"	.align	3\n"						\
-	"	.long	1b, 3b\n"					\
-	"	.previous"						\
-	: "+r" (err)							\
-	: "r" (x), "r" (addr), "i" (-EFAULT)				\
-	: "cc")
+#define __put_user_asm(inst, x, addr, err)				\
+	__asm__ __volatile__ (						\
+		"1:	"inst"	%1,[%2]\n"				\
+		"2:\n"							\
+		"	.section .fixup,\"ax\"\n"			\
+		"	.align	2\n"					\
+		"3:	move	%0, %3\n"				\
+		"	b	2b\n"					\
+		"	.previous\n"					\
+		"	.section __ex_table,\"a\"\n"			\
+		"	.align	3\n"					\
+		"	.long	1b, 3b\n"				\
+		"	.previous"					\
+		: "+r" (err)						\
+		: "r" (x), "r" (addr), "i" (-EFAULT)			\
+		: "cc")
 
 #ifdef __NDS32_EB__
 #define __pu_reg_oper0 "%H2"
@@ -239,23 +243,24 @@ do {									\
 #endif
 
 #define __put_user_asm_dword(x, addr, err) 				\
-	asm volatile(			    				\
-	"\n1:\tswi " __pu_reg_oper0 ",[%1]\n"				\
-	"\n2:\tswi " __pu_reg_oper1 ",[%1+4]\n"				\
-	"3:\n"								\
-	"	.section .fixup,\"ax\"\n"				\
-	"	.align	2\n"						\
-	"4:	move	%0, %3\n"					\
-	"	b	3b\n"						\
-	"	.previous\n"						\
-	"	.section __ex_table,\"a\"\n"				\
-	"	.align	3\n"						\
-	"	.long	1b, 4b\n"					\
-	"	.long	2b, 4b\n"					\
-	"	.previous"						\
-	: "+r"(err)                					\
-	: "r"(addr), "r"(x), "i"(-EFAULT) 				\
-	: "cc")
+	__asm__ __volatile__ (						\
+		"\n1:\tswi " __pu_reg_oper0 ",[%1]\n"			\
+		"\n2:\tswi " __pu_reg_oper1 ",[%1+4]\n"			\
+		"3:\n"							\
+		"	.section .fixup,\"ax\"\n"			\
+		"	.align	2\n"					\
+		"4:	move	%0, %3\n"				\
+		"	b	3b\n"					\
+		"	.previous\n"					\
+		"	.section __ex_table,\"a\"\n"			\
+		"	.align	3\n"					\
+		"	.long	1b, 4b\n"				\
+		"	.long	2b, 4b\n"				\
+		"	.previous"					\
+		: "+r"(err)						\
+		: "r"(addr), "r"(x), "i"(-EFAULT)			\
+		: "cc")
+
 extern unsigned long __arch_clear_user(void __user * addr, unsigned long n);
 extern long strncpy_from_user(char *dest, const char __user * src, long count);
 extern __must_check long strlen_user(const char __user * str);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] nds32: Extract the checking and getting pointer to a macro
  2018-08-13  9:26 [PATCH 0/3] Fix get_user and put_user pointer issue Zong Li
  2018-08-13  9:26 ` [PATCH 1/3] nds32: Fix get_user/put_user macro expand pointer problem Zong Li
  2018-08-13  9:26 ` [PATCH 2/3] nds32: Clean up the coding style Zong Li
@ 2018-08-13  9:26 ` Zong Li
  2018-08-21  7:03 ` [PATCH 0/3] Fix get_user and put_user pointer issue Greentime Hu
  3 siblings, 0 replies; 5+ messages in thread
From: Zong Li @ 2018-08-13  9:26 UTC (permalink / raw)
  To: green.hu, deanbo422, linux-kernel; +Cc: zongbox, Zong Li

Signed-off-by: Zong Li <zong@andestech.com>
---
 arch/nds32/include/asm/uaccess.h | 80 ++++++++++++++++++++--------------------
 1 file changed, 41 insertions(+), 39 deletions(-)

diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uaccess.h
index e1a2b5b..362a32d 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(); 						\
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] Fix get_user and put_user pointer issue
  2018-08-13  9:26 [PATCH 0/3] Fix get_user and put_user pointer issue Zong Li
                   ` (2 preceding siblings ...)
  2018-08-13  9:26 ` [PATCH 3/3] nds32: Extract the checking and getting pointer to a macro Zong Li
@ 2018-08-21  7:03 ` Greentime Hu
  3 siblings, 0 replies; 5+ messages in thread
From: Greentime Hu @ 2018-08-21  7:03 UTC (permalink / raw)
  To: Zong Li; +Cc: Vincent Chen, Linux Kernel Mailing List, Zong Li

Zong Li <zong@andestech.com> 於 2018年8月13日 週一 下午5:27寫道:
>
> These patches fix the issue of expand macro with pointer argument,
> clean up the coding style and refactor the macro by extracting the
> checking and getting pointer to another macro definition.
>
>
> Zong Li (3):
>   nds32: Fix get_user/put_user macro expand pointer problem
>   nds32: Clean up the coding style
>   nds32: Extract the checking and getting pointer to a macro
>
>  arch/nds32/include/asm/uaccess.h | 229 ++++++++++++++++++++-------------------
>  1 file changed, 119 insertions(+), 110 deletions(-)
>
Acked-by: Greentime Hu <greentime@andestech.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-21  7:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-13  9:26 [PATCH 0/3] Fix get_user and put_user pointer issue Zong Li
2018-08-13  9:26 ` [PATCH 1/3] nds32: Fix get_user/put_user macro expand pointer problem Zong Li
2018-08-13  9:26 ` [PATCH 2/3] nds32: Clean up the coding style Zong Li
2018-08-13  9:26 ` [PATCH 3/3] nds32: Extract the checking and getting pointer to a macro Zong Li
2018-08-21  7:03 ` [PATCH 0/3] Fix get_user and put_user pointer issue Greentime Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).