From: Simon Glass <simon.glass@canonical.com>
Move little-endian bit operations to asm-generic/bitops/le.h:
- find_next_zero_bit_le, find_next_bit_le
- test_bit_le, __set_bit_le, __clear_bit_le
- __test_and_set_bit_le, __test_and_clear_bit_le
This matches the Linux kernel header organisation and removes duplicate
implementations 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 | 38 ++---------------
include/asm-generic/bitops/le.h | 76 +++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 35 deletions(-)
create mode 100644 include/asm-generic/bitops/le.h
@@ -204,15 +204,8 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block);
* We implement them in interface.c for sandbox.
*/
-/* Little-endian bit operations - use arch-provided find_next_zero_bit */
-#define find_next_zero_bit_le(addr, size, offset) \
- find_next_zero_bit((void *)addr, size, offset)
-#define __set_bit_le(nr, addr) set_bit(nr, addr)
-#define test_bit_le(nr, addr) test_bit(nr, addr)
-#define __test_and_clear_bit_le(nr, addr) \
- ({ int __old = test_bit(nr, addr); clear_bit(nr, addr); __old; })
-#define __test_and_set_bit_le(nr, addr) \
- ({ int __old = test_bit(nr, addr); set_bit(nr, addr); __old; })
+/* Little-endian bit operations - use asm-generic/bitops/le.h */
+#include <asm-generic/bitops/le.h>
/* KUNIT stub - use kunit/static_stub.h */
#include <kunit/static_stub.h>
@@ -1280,32 +1273,7 @@ struct buffer_head *__bread(struct block_device *bdev, sector_t block, unsigned
/* XArray is now in linux/xarray.h */
/* Per-CPU stubs are in linux/percpu.h */
-/* Bit operations for little-endian bitmaps */
-#define __clear_bit_le(bit, addr) clear_bit_le(bit, addr)
-
-static inline void clear_bit_le(int nr, void *addr)
-{
- unsigned char *p = (unsigned char *)addr + (nr >> 3);
-
- *p &= ~(1 << (nr & 7));
-}
-
-#define find_next_bit_le(addr, size, offset) \
- ext4_find_next_bit_le(addr, size, offset)
-
-static inline unsigned long ext4_find_next_bit_le(const void *addr,
- unsigned long size,
- unsigned long offset)
-{
- const unsigned char *p = addr;
- unsigned long bit;
-
- for (bit = offset; bit < size; bit++) {
- if (p[bit >> 3] & (1 << (bit & 7)))
- return bit;
- }
- return size;
-}
+/* Little-endian bit operations are in asm-generic/bitops/le.h */
/* atomic64 operations are now in asm-generic/atomic.h */
new file mode 100644
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Little-endian bitops for U-Boot
+ *
+ * Based on Linux include/asm-generic/bitops/le.h
+ */
+#ifndef _ASM_GENERIC_BITOPS_LE_H
+#define _ASM_GENERIC_BITOPS_LE_H
+
+#include <asm/bitops.h>
+
+/*
+ * Little-endian bit operations.
+ * These operate on byte boundaries regardless of CPU endianness.
+ */
+
+#define find_next_zero_bit_le(addr, size, offset) \
+ find_next_zero_bit((void *)(addr), (size), (offset))
+
+#define find_next_bit_le(addr, size, offset) \
+ ext4_find_next_bit_le((addr), (size), (offset))
+
+static inline int test_bit_le(int nr, const void *addr)
+{
+ return test_bit(nr, addr);
+}
+
+static inline void __set_bit_le(int nr, void *addr)
+{
+ set_bit(nr, addr);
+}
+
+static inline void __clear_bit_le(int nr, void *addr)
+{
+ clear_bit(nr, addr);
+}
+
+static inline int __test_and_set_bit_le(int nr, void *addr)
+{
+ int old = test_bit(nr, addr);
+
+ set_bit(nr, addr);
+ return old;
+}
+
+static inline int __test_and_clear_bit_le(int nr, void *addr)
+{
+ int old = test_bit(nr, addr);
+
+ clear_bit(nr, addr);
+ return old;
+}
+
+/*
+ * ext4_find_next_bit_le - find next set bit in little-endian bitmap
+ * @addr: bitmap address
+ * @size: bitmap size in bits
+ * @offset: starting bit position
+ *
+ * Return: bit position of next set bit, or @size if none found
+ */
+static inline unsigned long ext4_find_next_bit_le(const void *addr,
+ unsigned long size,
+ unsigned long offset)
+{
+ const unsigned char *p = addr;
+ unsigned long bit;
+
+ for (bit = offset; bit < size; bit++) {
+ if (p[bit >> 3] & (1 << (bit & 7)))
+ return bit;
+ }
+ return size;
+}
+
+#endif /* _ASM_GENERIC_BITOPS_LE_H */