[Concept,02/26] linux: Move common types to types.h

Message ID 20251222115639.700578-3-sjg@u-boot.org
State New
Headers
Series fs: ext4l: Add support for mounting ext4 filesystems (part G) |

Commit Message

Simon Glass Dec. 22, 2025, 11:56 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move ktime_t, sector_t, blkcnt_t, atomic_t, and atomic64_t to
linux/types.h to match Linux kernel header organisation.

Remove the duplicate definitions from linux/compat.h and
fs/ext4l/ext4_uboot.h since they are now in the canonical location.

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

 fs/ext4l/ext4_uboot.h  | 24 ++++++++++--------------
 include/linux/compat.h | 16 +---------------
 include/linux/types.h  | 14 ++++++++++++++
 3 files changed, 25 insertions(+), 29 deletions(-)
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 1ad9ad7f47a..d0e60c02d77 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -2,6 +2,9 @@ 
 /*
  * U-Boot compatibility header for ext4l filesystem
  *
+ * Copyright 2025 Canonical Ltd
+ * Written by Simon Glass <simon.glass@canonical.com>
+ *
  * This provides minimal definitions to allow Linux ext4 code to compile
  * in U-Boot.
  */
@@ -52,8 +55,11 @@  struct timespec64 {
 	long tv_nsec;
 };
 
-/* ktime_t - kernel time type */
-typedef s64 ktime_t;
+/*
+ * ktime_t, sector_t are in linux/types.h
+ * atomic_t, atomic64_t are in asm-generic/atomic.h
+ */
+#include <asm-generic/atomic.h>
 
 /* Jiffy constants */
 #define MAX_JIFFY_OFFSET	((~0UL >> 1) - 1)
@@ -61,16 +67,7 @@  typedef s64 ktime_t;
 /* Block device name size */
 #define BDEVNAME_SIZE		32
 
-/* Atomic types - stubs for single-threaded U-Boot */
-typedef struct { int counter; } atomic_t;
-typedef struct { long counter; } atomic64_t;
-
-#define atomic_read(v)		((v)->counter)
-#define atomic_set(v, i)	((v)->counter = (i))
-#define atomic_inc(v)		((v)->counter++)
-#define atomic_dec(v)		((v)->counter--)
-#define atomic64_read(v)	((v)->counter)
-#define atomic64_set(v, i)	((v)->counter = (i))
+/* Extra atomic operations not in asm-generic/atomic.h */
 #define atomic_dec_if_positive(v)	(--(v)->counter)
 
 /* SMP stubs - U-Boot is single-threaded */
@@ -510,8 +507,7 @@  struct sb_writers {
 /* mapping_large_folio_support stub */
 #define mapping_large_folio_support(m)	(0)
 
-/* sector_t - needed before buffer_head.h */
-typedef unsigned long sector_t;
+/* sector_t is now in linux/types.h */
 
 /* Buffer head - from linux/buffer_head.h */
 #include <linux/buffer_head.h>
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 26f0ef3f101..df67b775b5b 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -110,21 +110,7 @@  static inline void led_trigger_event(struct led_trigger *trigger,
 /* uapi/linux/limits.h */
 #define XATTR_LIST_MAX 65536	/* size of extended attribute namelist (64k) */
 
-/**
- * The type used for indexing onto a disc or disc partition.
- *
- * Linux always considers sectors to be 512 bytes long independently
- * of the devices real block size.
- *
- * blkcnt_t is the type of the inode's block count.
- */
-#ifdef CONFIG_LBDAF
-typedef u64 sector_t;
-typedef u64 blkcnt_t;
-#else
-typedef unsigned long sector_t;
-typedef unsigned long blkcnt_t;
-#endif
+/* sector_t and blkcnt_t are now defined in linux/types.h */
 
 
 /* character device */
diff --git a/include/linux/types.h b/include/linux/types.h
index 9df930afd13..957284d37ab 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -151,6 +151,20 @@  typedef __u32 __bitwise __wsum;
 
 typedef unsigned __bitwise__	gfp_t;
 
+/* Nanosecond scalar representation for kernel time values */
+typedef s64	ktime_t;
+
+/**
+ * The type used for indexing onto a disc or disc partition.
+ *
+ * Linux always considers sectors to be 512 bytes long independently
+ * of the devices real block size.
+ *
+ * blkcnt_t is the type of the inode's block count.
+ */
+typedef u64 sector_t;
+typedef u64 blkcnt_t;
+
 #ifdef __linux__
 struct ustat {
 	__kernel_daddr_t	f_tfree;