compat: provide compat_ptr() on all architectures
authorArnd Bergmann <arnd@arndb.de>
Thu, 12 Dec 2019 17:15:25 +0000 (18:15 +0100)
committerArnd Bergmann <arnd@arndb.de>
Fri, 3 Jan 2020 08:32:51 +0000 (09:32 +0100)
In order to avoid needless #ifdef CONFIG_COMPAT checks,
move the compat_ptr() definition to linux/compat.h
where it can be seen by any file regardless of the
architecture.

Only s390 needs a special definition, this can use the
self-#define trick we have elsewhere.

Reviewed-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/arm64/include/asm/compat.h
arch/mips/include/asm/compat.h
arch/parisc/include/asm/compat.h
arch/powerpc/include/asm/compat.h
arch/powerpc/oprofile/backtrace.c
arch/s390/include/asm/compat.h
arch/sparc/include/asm/compat.h
arch/x86/include/asm/compat.h
include/linux/compat.h

index 7b4172ce497c20d9fdcadc533d13cb7a073a6503..935d2aa231bf066e21d08d15d11eb5246b40d203 100644 (file)
@@ -114,23 +114,6 @@ typedef u32                compat_sigset_word;
 
 #define COMPAT_OFF_T_MAX       0x7fffffff
 
-/*
- * A pointer passed in from user mode. This should not
- * be used for syscall parameters, just declare them
- * as pointers because the syscall entry code will have
- * appropriately converted them already.
- */
-
-static inline void __user *compat_ptr(compat_uptr_t uptr)
-{
-       return (void __user *)(unsigned long)uptr;
-}
-
-static inline compat_uptr_t ptr_to_compat(void __user *uptr)
-{
-       return (u32)(unsigned long)uptr;
-}
-
 #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
 #define COMPAT_MINSIGSTKSZ     2048
 
index c99166eadbde15bb32a6086f224ba3b083acb7a7..255afcdd79c94be96fd4116c20aeb609f80e5221 100644 (file)
@@ -100,24 +100,6 @@ typedef u32                compat_sigset_word;
 
 #define COMPAT_OFF_T_MAX       0x7fffffff
 
-/*
- * A pointer passed in from user mode. This should not
- * be used for syscall parameters, just declare them
- * as pointers because the syscall entry code will have
- * appropriately converted them already.
- */
-
-static inline void __user *compat_ptr(compat_uptr_t uptr)
-{
-       /* cast to a __user pointer via "unsigned long" makes sparse happy */
-       return (void __user *)(unsigned long)(long)uptr;
-}
-
-static inline compat_uptr_t ptr_to_compat(void __user *uptr)
-{
-       return (u32)(unsigned long)uptr;
-}
-
 static inline void __user *arch_compat_alloc_user_space(long len)
 {
        struct pt_regs *regs = (struct pt_regs *)
index e03e3c849f40aa40bd80eb98e6f0d2e5ed136a6a..2f4f66a3bac079aa6434514d91da8581891b9e3e 100644 (file)
@@ -173,23 +173,6 @@ struct compat_shmid64_ds {
 #define COMPAT_ELF_NGREG 80
 typedef compat_ulong_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
 
-/*
- * A pointer passed in from user mode. This should not
- * be used for syscall parameters, just declare them
- * as pointers because the syscall entry code will have
- * appropriately converted them already.
- */
-
-static inline void __user *compat_ptr(compat_uptr_t uptr)
-{
-       return (void __user *)(unsigned long)uptr;
-}
-
-static inline compat_uptr_t ptr_to_compat(void __user *uptr)
-{
-       return (u32)(unsigned long)uptr;
-}
-
 static __inline__ void __user *arch_compat_alloc_user_space(long len)
 {
        struct pt_regs *regs = &current->thread.regs;
index 74d0db511099c7888740131a5717fd6d7e811089..3e3cdfaa76c6a5cac084d7ce8451f9dcc6fd5535 100644 (file)
@@ -96,23 +96,6 @@ typedef u32          compat_sigset_word;
 
 #define COMPAT_OFF_T_MAX       0x7fffffff
 
-/*
- * A pointer passed in from user mode. This should not
- * be used for syscall parameters, just declare them
- * as pointers because the syscall entry code will have
- * appropriately converted them already.
- */
-
-static inline void __user *compat_ptr(compat_uptr_t uptr)
-{
-       return (void __user *)(unsigned long)uptr;
-}
-
-static inline compat_uptr_t ptr_to_compat(void __user *uptr)
-{
-       return (u32)(unsigned long)uptr;
-}
-
 static inline void __user *arch_compat_alloc_user_space(long len)
 {
        struct pt_regs *regs = current->thread.regs;
index 43245f4a9bcbfdc54e51e72daea508d6296bb7d7..6ffcb80cf844bfde5b16b8c5b04313d1c65e7d30 100644 (file)
@@ -9,7 +9,7 @@
 #include <linux/sched.h>
 #include <asm/processor.h>
 #include <linux/uaccess.h>
-#include <asm/compat.h>
+#include <linux/compat.h>
 #include <asm/oprofile_impl.h>
 
 #define STACK_SP(STACK)                *(STACK)
index 63b46e30b2c3733c07436c6b8b7f1d30b32bdbfa..9547cd5d6cdc21dad62657159b4a764a2bcbaee6 100644 (file)
@@ -177,11 +177,7 @@ static inline void __user *compat_ptr(compat_uptr_t uptr)
 {
        return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
 }
-
-static inline compat_uptr_t ptr_to_compat(void __user *uptr)
-{
-       return (u32)(unsigned long)uptr;
-}
+#define compat_ptr(uptr) compat_ptr(uptr)
 
 #ifdef CONFIG_COMPAT
 
index 30b1763580b1d1c86ecf9e7ec4d049a14171bed3..40a267b3bd5208ce26685b8ce7fe96d7bc703740 100644 (file)
@@ -125,23 +125,6 @@ typedef u32                compat_sigset_word;
 
 #define COMPAT_OFF_T_MAX       0x7fffffff
 
-/*
- * A pointer passed in from user mode. This should not
- * be used for syscall parameters, just declare them
- * as pointers because the syscall entry code will have
- * appropriately converted them already.
- */
-
-static inline void __user *compat_ptr(compat_uptr_t uptr)
-{
-       return (void __user *)(unsigned long)uptr;
-}
-
-static inline compat_uptr_t ptr_to_compat(void __user *uptr)
-{
-       return (u32)(unsigned long)uptr;
-}
-
 #ifdef CONFIG_COMPAT
 static inline void __user *arch_compat_alloc_user_space(long len)
 {
index 22c4dfe6599230378a3c9ac2ac6816a352390060..52e9f3480f690336359bb8af713fcaf39bf3dfa1 100644 (file)
@@ -177,23 +177,6 @@ typedef struct user_regs_struct compat_elf_gregset_t;
        (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
 #endif
 
-/*
- * A pointer passed in from user mode. This should not
- * be used for syscall parameters, just declare them
- * as pointers because the syscall entry code will have
- * appropriately converted them already.
- */
-
-static inline void __user *compat_ptr(compat_uptr_t uptr)
-{
-       return (void __user *)(unsigned long)uptr;
-}
-
-static inline compat_uptr_t ptr_to_compat(void __user *uptr)
-{
-       return (u32)(unsigned long)uptr;
-}
-
 static inline void __user *arch_compat_alloc_user_space(long len)
 {
        compat_uptr_t sp;
index 68f79d855c3d2cdf163e48cef0f23dd258e1ad1d..11083d84eb23ead8fcc62ca6277b9c904fe9bb6f 100644 (file)
@@ -958,4 +958,22 @@ static inline bool in_compat_syscall(void) { return false; }
 
 #endif /* CONFIG_COMPAT */
 
+/*
+ * A pointer passed in from user mode. This should not
+ * be used for syscall parameters, just declare them
+ * as pointers because the syscall entry code will have
+ * appropriately converted them already.
+ */
+#ifndef compat_ptr
+static inline void __user *compat_ptr(compat_uptr_t uptr)
+{
+       return (void __user *)(unsigned long)uptr;
+}
+#endif
+
+static inline compat_uptr_t ptr_to_compat(void __user *uptr)
+{
+       return (u32)(unsigned long)uptr;
+}
+
 #endif /* _LINUX_COMPAT_H */