[PATCH 00/16] ext4l: Move definitions to standard Linux headers
From: Simon Glass <simon.glass@canonical.com> This series continues the work of reducing fs/ext4l/ext4_uboot.h by moving definitions to their proper locations in include/linux/ headers. The ext4_uboot.h file provides Linux kernel compatibility for the ext4l filesystem driver. Many definitions were placed there temporarily during initial development. This series moves them to standard header locations matching the Linux kernel organisation: - Inode locking stubs and helpers to linux/fs.h - Compiler helpers (data_race, might_sleep) to linux/compiler.h and linux/kernel.h - Instruction pointer macros to linux/kernel.h - Credential types (user_namespace) to linux/cred.h - Filesystem types (fstrim_range) to linux/fs.h - Quota types (qsize_t) to linux/quotaops.h - String helpers (memweight) to linux/string.h - UID/GID helpers to new linux/highuid.h - Overflow helpers (struct_size) to new linux/overflow.h - Min/max helpers (umin) to linux/minmax.h - Slab helpers (KMEM_CACHE) to linux/slab.h - Rate limit helpers (WARN_RATELIMIT) to linux/ratelimit.h - Cycle counter (get_cycles) to new asm-generic/timex.h - Superblock definition (struct super_block) to new linux/fs/super_types.h This reduces ext4_uboot.h from 1666 to 1620 lines. Simon Glass (16): ext4l: Move inode locking stubs to linux/fs.h ext4l: Add linux/fs/super_types.h for struct super_block ext4l: Move inode and superblock helpers to linux/fs.h ext4l: Move data_race, might_sleep, fallthrough to standard headers ext4l: Move _RET_IP_, _THIS_IP_, BITS_PER_BYTE to standard headers ext4l: Move user_namespace to linux/cred.h ext4l: Move fstrim_range to linux/fs.h ext4l: Move qsize_t to linux/quotaops.h ext4l: Move memweight to linux/string.h ext4l: Add linux/highuid.h and move UID/GID helpers ext4l: Add linux/overflow.h and move struct_size ext4l: Move umin to linux/minmax.h ext4l: Move KMEM_CACHE macro to linux/slab.h ext4l: Use existing linux/nospec.h for array_index_nospec ext4l: Move WARN_RATELIMIT to linux/ratelimit.h ext4l: Add asm-generic/timex.h and move get_cycles fs/ext4l/ext4_uboot.h | 148 +++++++-------------------------- include/asm-generic/timex.h | 21 +++++ include/linux/compiler.h | 8 ++ include/linux/cred.h | 9 ++ include/linux/fs.h | 51 +++++++++++- include/linux/fs/super_types.h | 68 +++++++++++++++ include/linux/highuid.h | 19 +++++ include/linux/kernel.h | 17 ++++ include/linux/minmax.h | 18 ++++ include/linux/overflow.h | 23 +++++ include/linux/quotaops.h | 3 + include/linux/ratelimit.h | 9 ++ include/linux/slab.h | 10 +++ include/linux/string.h | 24 ++++++ 14 files changed, 308 insertions(+), 120 deletions(-) create mode 100644 include/asm-generic/timex.h create mode 100644 include/linux/fs/super_types.h create mode 100644 include/linux/highuid.h create mode 100644 include/linux/overflow.h -- 2.43.0 base-commit: 0a7a5e4a3d20d76f21de32292f847e05628b8a67 branch: extu
From: Simon Glass <simon.glass@canonical.com> U-Boot is single-threaded, so inode locking is a no-op. Move the stub macros (inode_lock, inode_unlock, inode_lock_shared, inode_unlock_shared, inode_trylock, inode_trylock_shared, inode_dio_wait, inode_lock_nested) and the I_MUTEX_* enum to include/linux/fs.h where they belong. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 15 ++------------- include/linux/fs.h | 13 +++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index ba462af45e4..8daf01779c5 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -719,15 +719,7 @@ static inline unsigned long memweight(const void *ptr, size_t bytes) #define bh_uptodate_or_lock(bh) (1) /* ext4_read_bh is stubbed in interface.c */ -/* Inode locking */ -#define inode_lock(inode) do { } while (0) -#define inode_unlock(inode) do { } while (0) -#define inode_lock_shared(inode) do { } while (0) -#define inode_unlock_shared(inode) do { } while (0) -#define inode_trylock(inode) (1) -#define inode_trylock_shared(inode) (1) -#define inode_dio_wait(inode) do { } while (0) - +/* Inode locking stubs are in linux/fs.h */ /* Lock debugging stubs are in linux/lockdep.h */ /* File operations */ @@ -1344,10 +1336,7 @@ static inline void super_set_uuid(struct super_block *sb, const u8 *uuid, #define xattr_handler_can_list(h, d) ({ (void)(h); (void)(d); 0; }) #define xattr_prefix(h) ({ (void)(h); (const char *)NULL; }) -/* I_MUTEX_* inode lock classes are in linux/fs.h */ - -/* Nested inode locking stub */ -#define inode_lock_nested(i, c) do { (void)(i); (void)(c); } while (0) +/* I_MUTEX_* constants and inode locking stubs are in linux/fs.h */ /* PF_MEMALLOC_NOFS is in linux/sched.h */ diff --git a/include/linux/fs.h b/include/linux/fs.h index 5c357cdacd2..6d8b9b5c79b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -270,4 +270,17 @@ enum { I_MUTEX_PARENT2, }; +/* + * Inode locking stubs - U-Boot is single-threaded, no locking needed. + */ +#define inode_lock(inode) do { (void)(inode); } while (0) +#define inode_unlock(inode) do { (void)(inode); } while (0) +#define inode_lock_shared(inode) do { (void)(inode); } while (0) +#define inode_unlock_shared(inode) do { (void)(inode); } while (0) +#define inode_trylock(inode) ({ (void)(inode); 1; }) +#define inode_trylock_shared(inode) ({ (void)(inode); 1; }) +#define inode_dio_wait(inode) do { (void)(inode); } while (0) +#define inode_lock_nested(inode, subclass) \ + do { (void)(inode); (void)(subclass); } while (0) + #endif /* _LINUX_FS_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Create include/linux/fs/super_types.h with the struct super_block definition and sb_rdonly() helper, matching the Linux kernel location. This allows other headers like linux/fs.h to access the full struct definition rather than just a forward declaration. Remove the duplicate definitions from ext4_uboot.h. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 41 ++------------------ include/linux/fs.h | 2 +- include/linux/fs/super_types.h | 68 ++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 include/linux/fs/super_types.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 8daf01779c5..d6b7acc66b3 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -194,8 +194,7 @@ extern struct user_namespace init_user_ns; /* might_sleep - stub */ #define might_sleep() do { } while (0) -/* sb_rdonly - check if filesystem is mounted read-only */ -#define sb_rdonly(sb) ((sb)->s_flags & SB_RDONLY) +/* sb_rdonly is in linux/super.h */ /* Trace stubs are now in ext4_trace.h */ @@ -328,10 +327,7 @@ void iput(struct inode *inode); /* SB_FREEZE_* constants are in linux/fs.h */ -/* sb_writers stub */ -struct sb_writers { - int frozen; -}; +/* sb_writers is in linux/super.h */ /* mapping_large_folio_support is in linux/pagemap.h */ @@ -424,38 +420,7 @@ struct fstrim_range { /* uuid_t is now in linux/uuid.h */ -/* Forward declarations for super_block */ -struct super_operations; -struct export_operations; -struct xattr_handler; - -/* super_block - minimal stub */ -struct super_block { - void *s_fs_info; - unsigned long s_blocksize; - unsigned char s_blocksize_bits; - unsigned long s_magic; - loff_t s_maxbytes; - unsigned long s_flags; - unsigned long s_iflags; /* Internal flags */ - struct rw_semaphore s_umount; - struct sb_writers s_writers; - struct block_device *s_bdev; - char s_id[32]; - struct dentry *s_root; - uuid_t s_uuid; - struct file_system_type *s_type; - s32 s_time_gran; /* Time granularity (ns) */ - time64_t s_time_min; /* Min supported time */ - time64_t s_time_max; /* Max supported time */ - const struct super_operations *s_op; - const struct export_operations *s_export_op; - const struct xattr_handler * const *s_xattr; - struct dentry *d_sb; /* Parent dentry - stub */ - - /* U-Boot: list of all inodes, for freeing on unmount */ - struct list_head s_inodes; -}; +/* super_block is now in linux/super.h */ /* Block device read-only check */ static inline int bdev_read_only(struct block_device *bdev) diff --git a/include/linux/fs.h b/include/linux/fs.h index 6d8b9b5c79b..f295086523a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -10,10 +10,10 @@ #include <linux/types.h> #include <linux/list.h> #include <linux/mutex.h> +#include <linux/fs/super_types.h> /* Forward declarations */ struct inode; -struct super_block; struct buffer_head; struct file; struct folio; diff --git a/include/linux/fs/super_types.h b/include/linux/fs/super_types.h new file mode 100644 index 00000000000..f3ed772ef40 --- /dev/null +++ b/include/linux/fs/super_types.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Superblock definitions + * + * Minimal version for U-Boot - based on Linux + */ +#ifndef _LINUX_FS_SUPER_TYPES_H +#define _LINUX_FS_SUPER_TYPES_H + +#include <linux/list.h> +#include <linux/rwsem.h> +#include <linux/time.h> +#include <linux/types.h> +#include <linux/uuid.h> + +/* Forward declarations */ +struct block_device; +struct dentry; +struct file_system_type; +struct super_operations; +struct export_operations; +struct xattr_handler; + +/* sb_writers stub */ +struct sb_writers { + int frozen; +}; + +/* super_block - filesystem superblock */ +struct super_block { + void *s_fs_info; + unsigned long s_blocksize; + unsigned char s_blocksize_bits; + unsigned long s_magic; + loff_t s_maxbytes; + unsigned long s_flags; + unsigned long s_iflags; /* Internal flags */ + struct rw_semaphore s_umount; + struct sb_writers s_writers; + struct block_device *s_bdev; + char s_id[32]; + struct dentry *s_root; + uuid_t s_uuid; + struct file_system_type *s_type; + s32 s_time_gran; /* Time granularity (ns) */ + time64_t s_time_min; /* Min supported time */ + time64_t s_time_max; /* Max supported time */ + const struct super_operations *s_op; + const struct export_operations *s_export_op; + const struct xattr_handler * const *s_xattr; + struct dentry *d_sb; /* Parent dentry - stub */ + + /* U-Boot: list of all inodes, for freeing on unmount */ + struct list_head s_inodes; +}; + +/* Superblock flags - also defined in linux/fs.h */ +#ifndef SB_RDONLY +#define SB_RDONLY (1 << 0) /* Read-only mount */ +#endif + +/* sb_rdonly - check if filesystem is mounted read-only */ +static inline bool sb_rdonly(const struct super_block *sb) +{ + return sb->s_flags & SB_RDONLY; +} + +#endif /* _LINUX_FS_SUPER_TYPES_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move sb_rdonly(), inode_is_locked(), i_size_write(), i_size_read(), i_blocksize(), inode_newsize_ok(), IS_SYNC(), IS_APPEND(), and IS_IMMUTABLE() macros to include/linux/fs.h where they belong. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 16 +++------------- include/linux/fs.h | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index d6b7acc66b3..0b3b2d6f2e5 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -284,10 +284,7 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode, #define sb_issue_zeroout(sb, blk, num, gfp) ({ (void)(sb); (void)(blk); (void)(num); (void)(gfp); 0; }) #define blkdev_issue_flush(bdev) ({ (void)(bdev); 0; }) -/* Inode locking - stubs */ -#define inode_is_locked(i) (1) -#define i_size_write(i, s) do { (i)->i_size = (s); } while (0) -#define i_size_read(i) ((i)->i_size) +/* inode_is_locked, i_size_write, i_size_read are in linux/fs.h */ /* spin_trylock is defined in linux/spinlock.h */ @@ -707,14 +704,9 @@ static inline unsigned long memweight(const void *ptr, size_t bytes) /* DAX device mapping check - always false in U-Boot */ #define daxdev_mapping_supported(f, i, d) ({ (void)(f); (void)(i); (void)(d); 1; }) -/* Inode time/size operations */ -#define inode_newsize_ok(i, s) ({ (void)(i); (void)(s); 0; }) +/* Inode time/size operations - inode_newsize_ok, i_blocksize, IS_SYNC are in linux/fs.h */ #define inode_set_ctime_current(i) ({ (void)(i); (struct timespec64){}; }) #define inode_set_mtime_to_ts(i, ts) ({ (void)(i); (ts); }) -#define i_blocksize(i) (1U << (i)->i_blkbits) - -/* IS_SYNC macro */ -#define IS_SYNC(inode) (0) /* Case-folding stubs - not supported in U-Boot */ #define sb_no_casefold_compat_fallback(sb) ({ (void)(sb); 1; }) @@ -925,9 +917,7 @@ extern struct inode *iget_locked(struct super_block *sb, unsigned long ino); #define generic_fillattr(m, req, i, s) do { } while (0) #define generic_fill_statx_atomic_writes(s, u_m, u_M, g) do { } while (0) -/* Inode flag macros */ -#define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) -#define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) +/* IS_APPEND, IS_IMMUTABLE are in linux/fs.h */ /* File operations */ #define file_update_time(f) do { } while (0) diff --git a/include/linux/fs.h b/include/linux/fs.h index f295086523a..75e4bd3e951 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -283,4 +283,26 @@ enum { #define inode_lock_nested(inode, subclass) \ do { (void)(inode); (void)(subclass); } while (0) +/* + * Inode helper functions + */ + +/* inode_is_locked - check if inode lock is held (always true in U-Boot) */ +#define inode_is_locked(i) (1) + +/* i_size accessors */ +#define i_size_write(i, s) do { (i)->i_size = (s); } while (0) +#define i_size_read(i) ((i)->i_size) + +/* i_blocksize - get block size from inode */ +#define i_blocksize(i) (1U << (i)->i_blkbits) + +/* inode_newsize_ok - check if new size is valid (always ok in U-Boot) */ +#define inode_newsize_ok(i, s) ({ (void)(i); (void)(s); 0; }) + +/* IS_SYNC, IS_APPEND, IS_IMMUTABLE - inode flag checks */ +#define IS_SYNC(inode) (0) +#define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) +#define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) + #endif /* _LINUX_FS_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move data_race() to linux/compiler.h and might_sleep() to linux/kernel.h where they belong. The fallthrough attribute is already provided by linux/compiler_attributes.h, so just remove the duplicate definition. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 10 +++------- include/linux/compiler.h | 8 ++++++++ include/linux/kernel.h | 8 ++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 0b3b2d6f2e5..564e63d6882 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -123,7 +123,7 @@ /* Pointer check macros */ #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= PAGE_SIZE) -#define data_race(expr) (expr) +/* data_race is in linux/compiler.h */ /* REQ_META, REQ_PRIO, REQ_RAHEAD are in linux/blk_types.h */ /* __GFP_MOVABLE, __GFP_FS are in linux/slab.h */ @@ -191,8 +191,7 @@ extern struct user_namespace init_user_ns; #define BUG_ON(cond) do { (void)(cond); } while (0) #define BUG() do { } while (0) -/* might_sleep - stub */ -#define might_sleep() do { } while (0) +/* might_sleep is in linux/kernel.h */ /* sb_rdonly is in linux/super.h */ @@ -642,10 +641,7 @@ struct dx_hash_info { do { } while (0) #endif -/* fallthrough annotation */ -#ifndef fallthrough -#define fallthrough __attribute__((__fallthrough__)) -#endif +/* fallthrough is in linux/compiler_attributes.h */ /* BUILD_BUG_ON is in linux/build_bug.h */ /* WARN_ON, WARN_ON_ONCE, WARN_ONCE are in linux/bug.h */ diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 09cea0e95e2..c1131fe886b 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -352,4 +352,12 @@ static inline void *offset_to_ptr(const int *off) /* &a[0] degrades to a pointer: a different type from an array */ #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) +/* + * data_race - mark data race intentional + * + * In U-Boot (single-threaded), no actual data races are possible, + * so just evaluate the expression. + */ +#define data_race(expr) (expr) + #endif /* __LINUX_COMPILER_H */ diff --git a/include/linux/kernel.h b/include/linux/kernel.h index d6cd54f20b9..0da0d4915ec 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -313,4 +313,12 @@ enum system_states { #define system_state SYSTEM_RUNNING +/* + * might_sleep - indicate that a function may sleep + * + * U-Boot is single-threaded and doesn't have a scheduler, so this is a no-op. + */ +#define might_sleep() do { } while (0) +#define might_sleep_if(cond) do { } while (0) + #endif -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move _RET_IP_ and _THIS_IP_ instruction pointer macros to linux/kernel.h where they belong. Remove the redundant BITS_PER_BYTE definition since it is already provided by linux/bitops.h. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 10 +++------- include/linux/kernel.h | 9 +++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 564e63d6882..4931bd25cea 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -113,7 +113,7 @@ /* lockdep stubs - needed before jbd2.h is included */ #include <linux/lockdep.h> -#define _THIS_IP_ ((unsigned long)0) +/* _THIS_IP_ is in linux/kernel.h */ /* completion - use Linux header */ #include <linux/completion.h> @@ -318,8 +318,7 @@ void iput(struct inode *inode); /* current task - from linux/sched.h */ #include <linux/sched.h> -/* _RET_IP_ - return instruction pointer */ -#define _RET_IP_ ((unsigned long)__builtin_return_address(0)) +/* _RET_IP_ is in linux/kernel.h */ /* SB_FREEZE_* constants are in linux/fs.h */ @@ -663,10 +662,7 @@ static inline unsigned long memweight(const void *ptr, size_t bytes) return ret; } -/* BITS_PER_BYTE */ -#ifndef BITS_PER_BYTE -#define BITS_PER_BYTE 8 -#endif +/* BITS_PER_BYTE is in linux/bitops.h */ /* extents.c stubs */ diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 0da0d4915ec..1442d620e9e 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -321,4 +321,13 @@ enum system_states { #define might_sleep() do { } while (0) #define might_sleep_if(cond) do { } while (0) +/* + * _RET_IP_ and _THIS_IP_ - instruction pointer macros + * + * _RET_IP_: return address of current function + * _THIS_IP_: current instruction pointer (stub - lockdep not used in U-Boot) + */ +#define _RET_IP_ ((unsigned long)__builtin_return_address(0)) +#define _THIS_IP_ ((unsigned long)0) + #endif -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move struct user_namespace stub and init_user_ns extern declaration to include/linux/cred.h where they belong with other credential-related definitions. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 6 +----- include/linux/cred.h | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 4931bd25cea..55a06d01996 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -174,11 +174,7 @@ static inline void memalloc_nofs_restore(unsigned int flags) { } /* IS_ENCRYPTED and FSCRYPT_SET_CONTEXT_MAX_SIZE are in ext4_fscrypt.h */ #define S_NOQUOTA 0 -/* User namespace - stub */ -struct user_namespace { - int dummy; -}; -extern struct user_namespace init_user_ns; +/* user_namespace and init_user_ns are in linux/cred.h */ /* * BUG_ON / BUG - stubs (not using linux/bug.h which panics) diff --git a/include/linux/cred.h b/include/linux/cred.h index a5afc267ba0..a3a972a5a73 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -50,4 +50,13 @@ struct cred { #define INVALID_UID ((kuid_t){-1}) #define INVALID_GID ((kgid_t){-1}) +/* + * User namespace stub - U-Boot doesn't have namespaces. + */ +struct user_namespace { + int dummy; +}; + +extern struct user_namespace init_user_ns; + #endif /* _LINUX_CRED_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move struct fstrim_range to include/linux/fs.h where it belongs in the Linux kernel header hierarchy. This structure is used for FITRIM ioctl. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 7 +------ include/linux/fs.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 55a06d01996..91d432d391d 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -395,12 +395,7 @@ typedef long long qsize_t; /* mnt_idmap - use linux/mnt_idmapping.h */ #include <linux/mnt_idmapping.h> -/* fstrim_range - stub */ -struct fstrim_range { - u64 start; - u64 len; - u64 minlen; -}; +/* fstrim_range is in linux/fs.h */ /* rw_semaphore - defined in linux/rwsem.h, include it */ #include <linux/rwsem.h> diff --git a/include/linux/fs.h b/include/linux/fs.h index 75e4bd3e951..1b0059ca1a7 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -305,4 +305,18 @@ enum { #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) +/** + * struct fstrim_range - fstrim ioctl argument + * @start: first byte to trim + * @len: number of bytes to trim + * @minlen: minimum extent length + * + * Used for FITRIM ioctl to trim unused blocks. + */ +struct fstrim_range { + u64 start; + u64 len; + u64 minlen; +}; + #endif /* _LINUX_FS_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the qsize_t typedef to include/linux/quotaops.h where it belongs with other quota-related definitions. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 3 +-- include/linux/quotaops.h | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 91d432d391d..79d70d78bfd 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -383,8 +383,7 @@ struct readahead_control; struct fiemap_extent_info; struct folio; -/* qsize_t - quota size type */ -typedef long long qsize_t; +/* qsize_t is in linux/quotaops.h */ /* blk_opf_t is in linux/blk_types.h */ diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h index b96e33887b8..ff455f4da7b 100644 --- a/include/linux/quotaops.h +++ b/include/linux/quotaops.h @@ -13,6 +13,9 @@ #include <linux/types.h> +/* qsize_t - quota size type for tracking disk space usage */ +typedef long long qsize_t; + struct inode; struct dentry; struct kqid; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the memweight() function to include/linux/string.h where it belongs in the Linux kernel header hierarchy. Use an inline popcount algorithm to avoid header include dependencies. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 12 +----------- include/linux/string.h | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 79d70d78bfd..6772fd8328f 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -640,17 +640,7 @@ struct dx_hash_info { /* strtomem_pad is in linux/string.h */ /* strscpy_pad is in linux/string.h */ -/* Memory weight - count set bits */ -static inline unsigned long memweight(const void *ptr, size_t bytes) -{ - unsigned long ret = 0; - const unsigned char *p = ptr; - size_t i; - - for (i = 0; i < bytes; i++) - ret += hweight8(p[i]); - return ret; -} +/* memweight is in linux/string.h */ /* BITS_PER_BYTE is in linux/bitops.h */ diff --git a/include/linux/string.h b/include/linux/string.h index 591d99c46a1..8dff476c60d 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -188,6 +188,30 @@ char *strreplace(char *str, char old, char new); */ #define strscpy_pad(dest, src) strncpy(dest, src, sizeof(dest)) +/** + * memweight - Count total number of bits set in a memory region + * @ptr: Pointer to memory region + * @bytes: Number of bytes to examine + * + * Return: Number of set bits in the memory region + */ +static inline unsigned long memweight(const void *ptr, size_t bytes) +{ + unsigned long ret = 0; + const unsigned char *p = ptr; + size_t i; + + for (i = 0; i < bytes; i++) { + /* Inline popcount for byte */ + unsigned char v = p[i]; + + v = v - ((v >> 1) & 0x55); + v = (v & 0x33) + ((v >> 2) & 0x33); + ret += (v + (v >> 4)) & 0x0f; + } + return ret; +} + #ifdef __cplusplus } #endif -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Create include/linux/highuid.h with the low_16_bits(), high_16_bits(), fs_high2lowuid(), and fs_high2lowgid() macros. These helpers are used for 16/32-bit UID/GID conversion in filesystem code. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 7 ++----- include/linux/highuid.h | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 include/linux/highuid.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 6772fd8328f..69c50d406f7 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -864,11 +864,8 @@ static inline unsigned int i_gid_read(const struct inode *inode) /* Device encoding helpers are now in linux/kdev_t.h */ #include <linux/kdev_t.h> -/* UID/GID bit helpers */ -#define low_16_bits(x) ((x) & 0xFFFF) -#define high_16_bits(x) (((x) >> 16) & 0xFFFF) -#define fs_high2lowuid(uid) ((uid) & 0xFFFF) -#define fs_high2lowgid(gid) ((gid) & 0xFFFF) +/* UID/GID bit helpers - use linux/highuid.h */ +#include <linux/highuid.h> /* Inode allocation/state operations */ extern struct inode *iget_locked(struct super_block *sb, unsigned long ino); diff --git a/include/linux/highuid.h b/include/linux/highuid.h new file mode 100644 index 00000000000..9bffa16b0aa --- /dev/null +++ b/include/linux/highuid.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * High UID/GID to low UID/GID conversion helpers + * + * Based on Linux highuid.h + */ +#ifndef _LINUX_HIGHUID_H +#define _LINUX_HIGHUID_H + +/* + * U-Boot doesn't support 16-bit UIDs/GIDs overflow handling, + * so these are simplified versions. + */ +#define low_16_bits(x) ((x) & 0xFFFF) +#define high_16_bits(x) (((x) >> 16) & 0xFFFF) +#define fs_high2lowuid(uid) ((uid) & 0xFFFF) +#define fs_high2lowgid(gid) ((gid) & 0xFFFF) + +#endif /* _LINUX_HIGHUID_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Create include/linux/overflow.h with the struct_size() macro that calculates the size of a structure with a trailing flexible array member. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 4 ++-- include/linux/overflow.h | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 include/linux/overflow.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 69c50d406f7..310d79227b7 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -923,8 +923,8 @@ extern struct inode *iget_locked(struct super_block *sb, unsigned long ino); ssize_t generic_read_dir(struct file *f, char __user *buf, size_t count, loff_t *ppos); -/* struct_size helper */ -#define struct_size(p, member, count) (sizeof(*(p)) + sizeof((p)->member[0]) * (count)) +/* struct_size - use linux/overflow.h */ +#include <linux/overflow.h> /* file_operations - extended for dir.c */ struct file_operations { diff --git a/include/linux/overflow.h b/include/linux/overflow.h new file mode 100644 index 00000000000..672377ede42 --- /dev/null +++ b/include/linux/overflow.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Overflow checking utilities + * + * Based on Linux overflow.h + */ +#ifndef _LINUX_OVERFLOW_H +#define _LINUX_OVERFLOW_H + +#include <linux/types.h> + +/** + * struct_size() - Calculate size of structure with trailing array member + * @p: Pointer to the structure + * @member: Name of the array member + * @count: Number of elements in the array + * + * Return: Total size of the structure including @count array elements + */ +#define struct_size(p, member, count) \ + (sizeof(*(p)) + sizeof((p)->member[0]) * (count)) + +#endif /* _LINUX_OVERFLOW_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the umin() macro to include/linux/minmax.h and add the matching umax() macro. These return the minimum/maximum of two unsigned values. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 3 +-- include/linux/minmax.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 310d79227b7..b50004bca55 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -699,8 +699,7 @@ struct dx_hash_info { /* indirect.c stubs */ -/* umin - unsigned min (Linux 6.x) */ -#define umin(x, y) ((x) < (y) ? (x) : (y)) +/* umin is in linux/minmax.h */ /* truncate_inode_pages is in linux/pagemap.h */ diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 52ce477459d..38b27c0232f 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -49,4 +49,22 @@ static inline bool in_range32(u32 val, u32 start, u32 len) return (val - start) < len; } +/** + * umin - Return the minimum of two unsigned values + * @x: First value + * @y: Second value + * + * Return: The smaller of @x and @y + */ +#define umin(x, y) ((x) < (y) ? (x) : (y)) + +/** + * umax - Return the maximum of two unsigned values + * @x: First value + * @y: Second value + * + * Return: The larger of @x and @y + */ +#define umax(x, y) ((x) > (y) ? (x) : (y)) + #endif /* _LINUX_MINMAX_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the KMEM_CACHE() convenience macro to include/linux/slab.h where it belongs with other kmem_cache functions. This macro creates a named cache for a specific structure type. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 3 +-- include/linux/slab.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index b50004bca55..484bd70222f 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -297,8 +297,7 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode, /* Memory allocation - use linux/slab.h which is already available */ #include <linux/slab.h> -/* KMEM_CACHE macro - use kmem_cache_create */ -#define KMEM_CACHE(s, flags) kmem_cache_create(#s, sizeof(struct s), 0, flags, NULL) +/* KMEM_CACHE macro is in linux/slab.h */ /* * RB tree operations - use real rbtree implementation from lib/rbtree.c diff --git a/include/linux/slab.h b/include/linux/slab.h index fb809063593..15d561f0527 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -117,6 +117,16 @@ struct kmem_cache { struct kmem_cache *get_mem(int element_sz); #define kmem_cache_create(a, sz, c, d, e) ({ (void)(a); (void)(e); get_mem(sz); }) + +/** + * KMEM_CACHE - shorthand for creating a named kmem_cache + * @s: struct type name + * @flags: cache creation flags + * + * Creates a cache for objects of type struct @s with the specified flags. + */ +#define KMEM_CACHE(s, flags) kmem_cache_create(#s, sizeof(struct s), 0, flags, NULL) + void *kmem_cache_alloc(struct kmem_cache *obj, gfp_t flag); static inline void *kmem_cache_zalloc(struct kmem_cache *obj, gfp_t flags) -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Remove the duplicate array_index_nospec definition and include the existing linux/nospec.h header instead. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 484bd70222f..e617fc41e30 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -1334,8 +1334,8 @@ static inline unsigned long ext4_find_next_bit_le(const void *addr, /* folio_get - now implemented in support.c */ -/* array_index_nospec - bounds checking without speculation (no-op in U-Boot) */ -#define array_index_nospec(index, size) (index) +/* array_index_nospec is in linux/nospec.h */ +#include <linux/nospec.h> /* atomic_inc_return and atomic_add_return are now in asm-generic/atomic.h */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Move the WARN_RATELIMIT macro to include/linux/ratelimit.h where it belongs with other rate-limiting definitions. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 3 +-- include/linux/ratelimit.h | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index e617fc41e30..49405877133 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -1329,8 +1329,7 @@ static inline unsigned long ext4_find_next_bit_le(const void *addr, /* sb_end_intwrite defined earlier */ -/* WARN_RATELIMIT - just evaluate condition, no warning in U-Boot */ -#define WARN_RATELIMIT(condition, ...) (condition) +/* WARN_RATELIMIT is in linux/ratelimit.h */ /* folio_get - now implemented in support.c */ diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h index 319f794f059..ca42c21406a 100644 --- a/include/linux/ratelimit.h +++ b/include/linux/ratelimit.h @@ -32,4 +32,13 @@ struct ratelimit_state { int ___ratelimit(struct ratelimit_state *rs, const char *func); void ratelimit_state_init(void *rs, int interval, int burst); +/** + * WARN_RATELIMIT - conditionally emit warning with rate limiting + * @condition: condition to check + * @...: printf-style format and arguments + * + * In U-Boot (no rate limiting), just evaluates the condition. + */ +#define WARN_RATELIMIT(condition, ...) (condition) + #endif /* _LINUX_RATELIMIT_H */ -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Create include/asm-generic/timex.h with the get_cycles() macro that returns 0 (U-Boot doesn't have a cycle counter). Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 4 ++-- include/asm-generic/timex.h | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 include/asm-generic/timex.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 49405877133..eadff92aecb 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -1322,8 +1322,8 @@ static inline unsigned long ext4_find_next_bit_le(const void *addr, /* atomic64 operations are now in asm-generic/atomic.h */ -/* CPU cycle counter stub */ -#define get_cycles() (0ULL) +/* get_cycles is in asm-generic/timex.h */ +#include <asm-generic/timex.h> /* folio_address is in linux/pagemap.h */ diff --git a/include/asm-generic/timex.h b/include/asm-generic/timex.h new file mode 100644 index 00000000000..005befd6b6d --- /dev/null +++ b/include/asm-generic/timex.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Generic timex definitions for U-Boot + * + * Based on Linux asm-generic/timex.h + */ +#ifndef _ASM_GENERIC_TIMEX_H +#define _ASM_GENERIC_TIMEX_H + +typedef unsigned long long cycles_t; + +/** + * get_cycles() - Get CPU cycle counter + * + * U-Boot doesn't have a cycle counter, so return 0. + * + * Return: 0 (stub) + */ +#define get_cycles() (0ULL) + +#endif /* _ASM_GENERIC_TIMEX_H */ -- 2.43.0
participants (1)
-
Simon Glass