[Concept,03/11] ext4l: Extract uaccess.h declarations into their own file

Message ID 20251216211817.4131167-4-sjg@u-boot.org
State New
Headers
Series ext4l: Add Linux compatibility headers |

Commit Message

Simon Glass Dec. 16, 2025, 9:18 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Create include/linux/uaccess.h with stub implementations for user-space
access functions. In U-Boot there's no user/kernel separation, so these
are simple memory copies.

Includes:
- copy_from_user()
- copy_to_user()
- get_user() / put_user()
- access_ok()

Update compat.h to include uaccess.h and remove the duplicate
declaration.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 include/linux/compat.h  |  3 +--
 include/linux/uaccess.h | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/uaccess.h
  

Patch

diff --git a/include/linux/compat.h b/include/linux/compat.h
index 12b4cfccdc5..d66ca200602 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -13,6 +13,7 @@ 
 #include <linux/err.h>
 #include <linux/export.h>
 #include <linux/kernel.h>
+#include <linux/uaccess.h>
 
 #ifdef CONFIG_XEN
 #include <xen/events.h>
@@ -239,8 +240,6 @@  typedef unsigned long blkcnt_t;
 
 struct work_struct {};
 
-unsigned long copy_from_user(void *dest, const void *src,
-			     unsigned long count);
 
 typedef unused_t spinlock_t;
 typedef int	wait_queue_head_t;
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
new file mode 100644
index 00000000000..96311e2c6f1
--- /dev/null
+++ b/include/linux/uaccess.h
@@ -0,0 +1,32 @@ 
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LINUX_UACCESS_H
+#define _LINUX_UACCESS_H
+
+#include <linux/types.h>
+#include <string.h>
+
+/*
+ * Stub definitions for Linux kernel user-space access functions.
+ * In U-Boot there's no user/kernel separation, so these are simple copies.
+ */
+
+static inline unsigned long copy_from_user(void *to, const void *from,
+					   unsigned long n)
+{
+	memcpy(to, from, n);
+	return 0;
+}
+
+static inline unsigned long copy_to_user(void *to, const void *from,
+					 unsigned long n)
+{
+	memcpy(to, from, n);
+	return 0;
+}
+
+#define get_user(x, ptr) ({ x = *(ptr); 0; })
+#define put_user(x, ptr) ({ *(ptr) = x; 0; })
+
+#define access_ok(addr, size)	1
+
+#endif /* _LINUX_UACCESS_H */