[Concept,05/15] ext4l: Implement little-endian bit operations

Message ID 20251230234134.906477-6-sjg@u-boot.org
State New
Headers
Series ext4l: Infrastructure and fixes for write support (part K) |

Commit Message

Simon Glass Dec. 30, 2025, 11:41 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The ext4 block allocator uses little-endian bit operations on block
bitmaps. Implement these operations by wrapping the existing
set/test/clear_bit() functions.

Add find_next_zero_bit() to search for free blocks in bitmaps.

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

 fs/ext4l/ext4_uboot.h | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 39bade68654..4ce98eeb7ed 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -349,13 +349,15 @@  struct buffer_head *sb_getblk(struct super_block *sb, sector_t block);
  * We implement them in interface.c for sandbox.
  */
 
-/* Little-endian bit operations */
-#define __set_bit_le(nr, addr)		((void)(nr), (void)(addr))
-#define test_bit_le(nr, addr)		({ (void)(nr); (void)(addr); 0; })
+/* Little-endian bit operations - use arch-provided find_next_zero_bit */
 #define find_next_zero_bit_le(addr, size, offset) \
-	({ (void)(addr); (void)(size); (offset); })
-#define __test_and_clear_bit_le(nr, addr) ({ (void)(nr); (void)(addr); 0; })
-#define __test_and_set_bit_le(nr, addr)	({ (void)(nr); (void)(addr); 0; })
+	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; })
 
 /* KUNIT stub */
 #define KUNIT_STATIC_STUB_REDIRECT(...)	do { } while (0)