[PATCH v5 03/12] xarray: move xas_result() and xa_zero_to_null() to the header

From: Andreas Hindborg

Date: Wed Sep 02 2026 - 09:48:58 EST


The functions xas_result() and xa_zero_to_null() are static in
lib/xarray.c. Upcoming Rust XArray changes need to call them from
Rust helper functions. Move them to include/linux/xarray.h as static
inline functions, following the approach of commit 79ada2ae6615
("xarray: extract helper from __xa_{insert,cmpxchg}").

No functional change.

Suggested-by: Tamir Duberstein <tamird@xxxxxxxxxx>
Assisted-by: LLM
Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
include/linux/xarray.h | 26 ++++++++++++++++++++++++++
lib/xarray.c | 12 ------------
2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index be850174e802e..db2520864aaa7 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -191,6 +191,17 @@ static inline bool xa_is_zero(const void *entry)
return unlikely(entry == XA_ZERO_ENTRY);
}

+/**
+ * xa_zero_to_null() - Convert an internal zero entry into a NULL pointer.
+ * @entry: XArray entry.
+ *
+ * Return: %NULL if @entry is a zero entry, @entry otherwise.
+ */
+static inline void *xa_zero_to_null(void *entry)
+{
+ return xa_is_zero(entry) ? NULL : entry;
+}
+
/**
* xa_is_err() - Report whether an XArray operation returned an error
* @entry: Result from calling an XArray function
@@ -1437,6 +1448,21 @@ static inline int xas_error(const struct xa_state *xas)
return xa_err(xas->xa_node);
}

+/**
+ * xas_result() - Extract the result of an XArray operation.
+ * @xas: XArray operation state.
+ * @curr: Entry returned by the operation.
+ *
+ * Return: @curr if the operation succeeded, the error encoded in @xas
+ * otherwise.
+ */
+static inline void *xas_result(struct xa_state *xas, void *curr)
+{
+ if (xas_error(xas))
+ curr = xas->xa_node;
+ return curr;
+}
+
/**
* xas_set_err() - Note an error in the xa_state.
* @xas: XArray operation state.
diff --git a/lib/xarray.c b/lib/xarray.c
index 9a8b4916540cf..cddb44f6b4ab2 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -437,11 +437,6 @@ static unsigned long max_index(void *entry)
return (XA_CHUNK_SIZE << xa_to_node(entry)->shift) - 1;
}

-static inline void *xa_zero_to_null(void *entry)
-{
- return xa_is_zero(entry) ? NULL : entry;
-}
-
static void xas_shrink(struct xa_state *xas)
{
struct xarray *xa = xas->xa;
@@ -1624,13 +1619,6 @@ void *xa_load(struct xarray *xa, unsigned long index)
}
EXPORT_SYMBOL(xa_load);

-static void *xas_result(struct xa_state *xas, void *curr)
-{
- if (xas_error(xas))
- curr = xas->xa_node;
- return curr;
-}
-
/**
* __xa_erase() - Erase this entry from the XArray while locked.
* @xa: XArray.

--
2.51.2