Now that we've got the same knob selecting inline vs outline copy_to_user()
and copy_from_user(), we can simplify the corresponding logic in the
uaccess.h.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
include/linux/uaccess.h | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 0ddd2806d7f5..19079588c78c 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -190,10 +190,6 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)
memset(to + (n - res), 0, res);
return res;
}
-#ifndef INLINE_COPY_USER
-extern __must_check unsigned long
-_copy_from_user(void *, const void __user *, unsigned long);
-#endif
static inline __must_check unsigned long
_inline_copy_to_user(void __user *to, const void *from, unsigned long n)
@@ -207,7 +203,13 @@ _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
}
return n;
}
-#ifndef INLINE_COPY_USER
+#ifdef INLINE_COPY_USER
+# define _copy_to_user _inline_copy_to_user
+# define _copy_from_user _inline_copy_from_user
+#else
+extern __must_check unsigned long
+_copy_from_user(void *, const void __user *, unsigned long);
+
extern __must_check unsigned long
_copy_to_user(void __user *, const void *, unsigned long);
#endif
@@ -217,11 +219,8 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
{
if (!check_copy_size(to, n, false))
return n;
-#ifdef INLINE_COPY_USER
- return _inline_copy_from_user(to, from, n);
-#else
+
return _copy_from_user(to, from, n);
-#endif
}
static __always_inline unsigned long __must_check
@@ -230,11 +229,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
if (!check_copy_size(from, n, true))
return n;
-#ifdef INLINE_COPY_USER
- return _inline_copy_to_user(to, from, n);
-#else
return _copy_to_user(to, from, n);
-#endif
}
#ifndef copy_mc_to_kernel
--
2.43.0
Le 25/03/2026 à 17:33, Yury Norov a écrit :
> Now that we've got the same knob selecting inline vs outline copy_to_user()
> and copy_from_user(), we can simplify the corresponding logic in the
> uaccess.h.
I think we should get rid of ifdefery completly, see below. And with
comment to previous patch,
__is_defined(INLINE_COPY_TO_USER)
becomes
!IS_ENABLED(CONFIG_ARCH_WANT_OUTLINE_USER_COPY)
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 327f967a24b8..02a05dd61a77 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -190,10 +190,9 @@ _inline_copy_from_user(void *to, const void __user
*from, unsigned long n)
memset(to + (n - res), 0, res);
return res;
}
-#ifndef INLINE_COPY_FROM_USER
+
extern __must_check unsigned long
_copy_from_user(void *, const void __user *, unsigned long);
-#endif
static inline __must_check unsigned long
_inline_copy_to_user(void __user *to, const void *from, unsigned long n)
@@ -207,21 +206,19 @@ _inline_copy_to_user(void __user *to, const void
*from, unsigned long n)
}
return n;
}
-#ifndef INLINE_COPY_TO_USER
+
extern __must_check unsigned long
_copy_to_user(void __user *, const void *, unsigned long);
-#endif
static __always_inline unsigned long __must_check
copy_from_user_common(void *to, const void __user *from, unsigned long
n, bool partial)
{
if (!check_copy_size(to, n, false))
return n;
-#ifdef INLINE_COPY_FROM_USER
- return _inline_copy_from_user(to, from, n);
-#else
- return _copy_from_user(to, from, n);
-#endif
+ if (__is_defined(INLINE_COPY_FROM_USER))
+ return _inline_copy_from_user(to, from, n);
+ else
+ return _copy_from_user(to, from, n);
}
static __always_inline unsigned long __must_check
@@ -242,11 +239,10 @@ copy_to_user_common(void __user *to, const void
*from, unsigned long n, bool par
if (!check_copy_size(from, n, true))
return n;
-#ifdef INLINE_COPY_TO_USER
- return _inline_copy_to_user(to, from, n);
-#else
- return _copy_to_user(to, from, n);
-#endif
+ if (__is_defined(INLINE_COPY_TO_USER))
+ return _inline_copy_to_user(to, from, n);
+ else
+ return _copy_to_user(to, from, n);
}
static __always_inline unsigned long __must_check
Christophe
On Wed, Mar 25, 2026 at 12:33:12PM -0400, Yury Norov wrote:
> Now that we've got the same knob selecting inline vs outline copy_to_user()
> and copy_from_user(), we can simplify the corresponding logic in the
> uaccess.h.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
Both patches are:
Tested-by: Alice Ryhl <aliceryhl@google.com>
But I can't help but think if it wouldn't be slightly better to split up
the first patch in a targeted Fixes: path that just fixes the FROM/TO
mixup, and a follow-up non-fix that actually deduplicates the two
ifdefs.
> @@ -217,11 +219,8 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
> {
> if (!check_copy_size(to, n, false))
> return n;
> -#ifdef INLINE_COPY_USER
> - return _inline_copy_from_user(to, from, n);
> -#else
> +
> return _copy_from_user(to, from, n);
> -#endif
Spurious extra empty line here?
Alice
© 2016 - 2026 Red Hat, Inc.