From: Simon Glass <simon.glass@canonical.com> Create linux/hash.h with hash_64() and hash_32() hash functions. Update ext4_uboot.h to use the new header instead of duplicating the hash_64 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 | 6 +++--- include/linux/hash.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 include/linux/hash.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 4bc25b73f76..b861079bf48 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -901,8 +901,8 @@ void mapping_clear_folio_cache(struct address_space *mapping); /* try_cmpxchg is now in asm-generic/atomic.h */ -/* hash_64 - simple 64-bit hash */ -#define hash_64(val, bits) ((unsigned long)((val) >> (64 - (bits)))) +/* hash_64 - use linux/hash.h */ +#include <linux/hash.h> /* Dentry operations are now in linux/dcache.h */ #define finish_open_simple(f, e) (e) @@ -1820,7 +1820,7 @@ int ext4_update_overhead(struct super_block *sb, bool force); /* fsmap is now in linux/fsmap.h */ #include <linux/fsmap.h> -/* list_sort and sort stubs for fsmap.c */ +/* list_sort and sort stubs for fsmap.c - not used in U-Boot */ #define list_sort(priv, head, cmp) \ do { (void)(priv); (void)(head); (void)(cmp); } while (0) #define sort(base, num, size, cmp, swap) \ diff --git a/include/linux/hash.h b/include/linux/hash.h new file mode 100644 index 00000000000..276619ca310 --- /dev/null +++ b/include/linux/hash.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Hash functions for U-Boot + * + * Based on Linux hash.h - fast hashing routines. + */ +#ifndef _LINUX_HASH_H +#define _LINUX_HASH_H + +#include <linux/types.h> + +/** + * hash_64() - 64-bit hash function + * @val: value to hash + * @bits: number of bits in result + * + * Simple hash by shifting. In Linux this uses multiplication by a + * golden ratio constant, but for U-Boot a simple shift suffices. + * + * Return: hash value with @bits significant bits + */ +#define hash_64(val, bits) ((unsigned long)((val) >> (64 - (bits)))) + +/** + * hash_32() - 32-bit hash function + * @val: value to hash + * @bits: number of bits in result + * + * Return: hash value with @bits significant bits + */ +#define hash_32(val, bits) ((unsigned int)((val) >> (32 - (bits)))) + +#endif /* _LINUX_HASH_H */ -- 2.43.0