Re: [PATCH] MIPS: uaccess: Reduce number of nested macros

2021-04-12 Thread Thomas Bogendoerfer
On Thu, Apr 08, 2021 at 08:14:37PM +0200, Thomas Bogendoerfer wrote:
> Clean up macros even further after removal get_fs/set_fs.
> 
> Signed-off-by: Thomas Bogendoerfer 
> ---
>  arch/mips/include/asm/uaccess.h | 157 +++-
>  1 file changed, 71 insertions(+), 86 deletions(-)

applied to mips-next.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.[ RFC1925, 2.3 ]


Re: [PATCH] MIPS: uaccess: Reduce number of nested macros

2021-04-08 Thread Thomas Bogendoerfer
On Thu, Apr 08, 2021 at 09:46:11PM +0200, Christoph Hellwig wrote:
> > +#define put_user(x, ptr)   \
> > +({ \
> > +   __typeof__(*(ptr)) __user *__p = (ptr); \
> > +   \
> > +   might_fault();  \
> > +   access_ok(__p, sizeof(*__p)) ?  \
> > +   __put_user((x), __p) :  \
> > +   -EFAULT;\
> 
> Why not merge this into a single line, which seems a little more
> readable:
> 
>   access_ok(__p, sizeof(*__p)) ? __put_user((x), __p) : -EFAULT;  \

I just copied the riscv version ;-) I'll make it one line before applying.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.[ RFC1925, 2.3 ]


Re: [PATCH] MIPS: uaccess: Reduce number of nested macros

2021-04-08 Thread Christoph Hellwig
> +#define put_user(x, ptr) \
> +({   \
> + __typeof__(*(ptr)) __user *__p = (ptr); \
> + \
> + might_fault();  \
> + access_ok(__p, sizeof(*__p)) ?  \
> + __put_user((x), __p) :  \
> + -EFAULT;\

Why not merge this into a single line, which seems a little more
readable:

access_ok(__p, sizeof(*__p)) ? __put_user((x), __p) : -EFAULT;  \

Same for the get_user side.

Otherwise looks great:

Reviewed-by: Christoph Hellwig 


[PATCH] MIPS: uaccess: Reduce number of nested macros

2021-04-08 Thread Thomas Bogendoerfer
Clean up macros even further after removal get_fs/set_fs.

Signed-off-by: Thomas Bogendoerfer 
---
 arch/mips/include/asm/uaccess.h | 157 +++-
 1 file changed, 71 insertions(+), 86 deletions(-)

diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
index 91bc7fb7dca1..e0dedd47e4e6 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -102,8 +102,15 @@ static inline int __access_ok(const void __user *p, 
unsigned long size)
  *
  * Returns zero on success, or -EFAULT on error.
  */
-#define put_user(x,ptr) \
-   __put_user_check((x), (ptr), sizeof(*(ptr)))
+#define put_user(x, ptr)   \
+({ \
+   __typeof__(*(ptr)) __user *__p = (ptr); \
+   \
+   might_fault();  \
+   access_ok(__p, sizeof(*__p)) ?  \
+   __put_user((x), __p) :  \
+   -EFAULT;\
+})
 
 /*
  * get_user: - Get a simple variable from user space.
@@ -123,8 +130,15 @@ static inline int __access_ok(const void __user *p, 
unsigned long size)
  * Returns zero on success, or -EFAULT on error.
  * On error, the variable @x is set to zero.
  */
-#define get_user(x,ptr) \
-   __get_user_check((x), (ptr), sizeof(*(ptr)))
+#define get_user(x, ptr)   \
+({ \
+   const __typeof__(*(ptr)) __user *__p = (ptr);   \
+   \
+   might_fault();  \
+   access_ok(__p, sizeof(*__p)) ?  \
+   __get_user((x), __p) :  \
+   ((x) = 0, -EFAULT); \
+})
 
 /*
  * __put_user: - Write a simple value into user space, with less checking.
@@ -146,8 +160,32 @@ static inline int __access_ok(const void __user *p, 
unsigned long size)
  *
  * Returns zero on success, or -EFAULT on error.
  */
-#define __put_user(x,ptr) \
-   __put_user_nocheck((x), (ptr), sizeof(*(ptr)))
+#define __put_user(x, ptr) \
+({ \
+   __typeof__(*(ptr)) __user *__pu_ptr = (ptr);\
+   __typeof__(*(ptr)) __pu_val = (x);  \
+   int __pu_err = 0;   \
+   \
+   __chk_user_ptr(__pu_ptr);   \
+   switch (sizeof(*__pu_ptr)) {\
+   case 1: \
+   __put_data_asm(user_sb, __pu_ptr);  \
+   break;  \
+   case 2: \
+   __put_data_asm(user_sh, __pu_ptr);  \
+   break;  \
+   case 4: \
+   __put_data_asm(user_sw, __pu_ptr);  \
+   break;  \
+   case 8: \
+   __PUT_DW(user_sd, __pu_ptr);\
+   break;  \
+   default:\
+   BUILD_BUG();\
+   }   \
+   \
+   __pu_err;   \
+})
 
 /*
  * __get_user: - Get a simple variable from user space, with less checking.
@@ -170,8 +208,31 @@ static inline int __access_ok(const void __user *p, 
unsigned long size)
  * Returns zero on success, or -EFAULT on error.
  * On error, the variable @x is set to zero.
  */
-#define __get_user(x,ptr) \
-   __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
+#define __get_user(x, ptr) \
+({ \
+   const __typeof__(*(ptr)) __user *__gu_ptr = (ptr);  \
+   int __gu_err = 0;