[Concept,14/19] linux: Add xarray.h header with XArray stubs

Message ID 20260117011448.3007171-15-sjg@u-boot.org
State New
Headers
Series ext4l: Reduce ext4_uboot.h size by moving code to include/linux |

Commit Message

Simon Glass Jan. 17, 2026, 1:14 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move XArray type and operation stubs to a dedicated header file
that mirrors the Linux kernel organisation.

xarray.h provides:
- xa_mark_t type for XArray marks
- struct xarray (empty stub)
- xa_init(), xa_destroy() - initialisation stubs
- xa_load(), xa_erase(), xa_insert() - access stubs
- xa_empty() - always returns true
- xa_for_each(), xa_for_each_range() - iteration macros (iterate zero times)

These are stubs since U-Boot doesn't use the XArray data structure.

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

 fs/ext4l/ext4_uboot.h  | 26 +++-------------------
 include/linux/xarray.h | 50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 23 deletions(-)
 create mode 100644 include/linux/xarray.h
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 655d64398d5..97bcc48d922 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -915,10 +915,9 @@  static inline int in_range(unsigned long val, unsigned long start,
 
 /* folio and pagemap - use linux/pagemap.h */
 #include <linux/pagemap.h>
+#include <linux/xarray.h>
 
-/* xa_mark_t - xarray mark type */
-typedef unsigned int xa_mark_t;
-
+/* wbc_to_tag - convert writeback control to pagecache tag */
 static inline xa_mark_t wbc_to_tag(struct writeback_control *wbc)
 {
 	if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
@@ -1673,28 +1672,9 @@  struct buffer_head *__bread(struct block_device *bdev, sector_t block, unsigned
  * Stubs for mballoc.c
  */
 
-/* XArray stub structure */
-struct xarray {
-	int dummy;
-};
-
+/* XArray is now in linux/xarray.h */
 /* Per-CPU stubs are in linux/percpu.h */
 
-/* XArray function stubs */
-#define xa_init(xa)			do { } while (0)
-#define xa_destroy(xa)			do { } while (0)
-#define xa_load(xa, index)		((void *)NULL)
-#define xa_erase(xa, index)		do { (void)(xa); (void)(index); } while (0)
-#define xa_insert(xa, index, entry, gfp) ({ (void)(xa); (void)(index); (void)(entry); (void)(gfp); 0; })
-#define xa_empty(xa)			({ (void)(xa); 1; })
-
-/* XArray iteration stubs - iterate zero times */
-#define xa_for_each(xa, index, entry) \
-	for ((index) = 0, (entry) = NULL; 0; )
-
-#define xa_for_each_range(xa, index, entry, start, end) \
-	for ((index) = (start), (entry) = NULL; 0; )
-
 /* Bit operations for little-endian bitmaps */
 #define __clear_bit_le(bit, addr)	clear_bit_le(bit, addr)
 
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
new file mode 100644
index 00000000000..49c00ed9380
--- /dev/null
+++ b/include/linux/xarray.h
@@ -0,0 +1,50 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * XArray stubs for U-Boot
+ *
+ * U-Boot doesn't have the XArray data structure, so these are stubs.
+ */
+#ifndef _LINUX_XARRAY_H
+#define _LINUX_XARRAY_H
+
+#include <linux/types.h>
+
+/**
+ * typedef xa_mark_t - XArray mark type
+ *
+ * Used to tag entries in an XArray.
+ */
+typedef unsigned int xa_mark_t;
+
+/**
+ * struct xarray - XArray data structure
+ *
+ * U-Boot stub - the XArray is not used.
+ */
+struct xarray {
+	int dummy;
+};
+
+/* XArray initialisation/destruction stubs */
+#define xa_init(xa)		do { } while (0)
+#define xa_destroy(xa)		do { } while (0)
+
+/* XArray lookup stubs - always return NULL */
+#define xa_load(xa, index)	((void *)NULL)
+
+/* XArray modification stubs */
+#define xa_erase(xa, index)	do { (void)(xa); (void)(index); } while (0)
+#define xa_insert(xa, index, entry, gfp) \
+	({ (void)(xa); (void)(index); (void)(entry); (void)(gfp); 0; })
+
+/* XArray query stubs - always empty */
+#define xa_empty(xa)		({ (void)(xa); 1; })
+
+/* XArray iteration stubs - iterate zero times */
+#define xa_for_each(xa, index, entry) \
+	for ((index) = 0, (entry) = NULL; 0; )
+
+#define xa_for_each_range(xa, index, entry, start, end) \
+	for ((index) = (start), (entry) = NULL; 0; )
+
+#endif /* _LINUX_XARRAY_H */