]> git.ipfire.org Git - thirdparty/linux.git/blobdiff - lib/xarray.c
Merge tag 'mm-hotfixes-stable-2024-06-07-15-24' of git://git.kernel.org/pub/scm/linux...
[thirdparty/linux.git] / lib / xarray.c
index 5e7d6334d70d7d1e16291a15fd2f5a45a83f81b9..32d4bac8c94ca13e11f350c6bcfcacc2040d0359 100644 (file)
@@ -200,7 +200,8 @@ static void *xas_start(struct xa_state *xas)
        return entry;
 }
 
-static void *xas_descend(struct xa_state *xas, struct xa_node *node)
+static __always_inline void *xas_descend(struct xa_state *xas,
+                                       struct xa_node *node)
 {
        unsigned int offset = get_offset(xas->xa_index, node);
        void *entry = xa_entry(xas->xa, node, offset);
@@ -1765,39 +1766,52 @@ unlock:
 EXPORT_SYMBOL(xa_store_range);
 
 /**
- * xa_get_order() - Get the order of an entry.
- * @xa: XArray.
- * @index: Index of the entry.
+ * xas_get_order() - Get the order of an entry.
+ * @xas: XArray operation state.
+ *
+ * Called after xas_load, the xas should not be in an error state.
  *
  * Return: A number between 0 and 63 indicating the order of the entry.
  */
-int xa_get_order(struct xarray *xa, unsigned long index)
+int xas_get_order(struct xa_state *xas)
 {
-       XA_STATE(xas, xa, index);
-       void *entry;
        int order = 0;
 
-       rcu_read_lock();
-       entry = xas_load(&xas);
-
-       if (!entry)
-               goto unlock;
-
-       if (!xas.xa_node)
-               goto unlock;
+       if (!xas->xa_node)
+               return 0;
 
        for (;;) {
-               unsigned int slot = xas.xa_offset + (1 << order);
+               unsigned int slot = xas->xa_offset + (1 << order);
 
                if (slot >= XA_CHUNK_SIZE)
                        break;
-               if (!xa_is_sibling(xas.xa_node->slots[slot]))
+               if (!xa_is_sibling(xa_entry(xas->xa, xas->xa_node, slot)))
                        break;
                order++;
        }
 
-       order += xas.xa_node->shift;
-unlock:
+       order += xas->xa_node->shift;
+       return order;
+}
+EXPORT_SYMBOL_GPL(xas_get_order);
+
+/**
+ * xa_get_order() - Get the order of an entry.
+ * @xa: XArray.
+ * @index: Index of the entry.
+ *
+ * Return: A number between 0 and 63 indicating the order of the entry.
+ */
+int xa_get_order(struct xarray *xa, unsigned long index)
+{
+       XA_STATE(xas, xa, index);
+       int order = 0;
+       void *entry;
+
+       rcu_read_lock();
+       entry = xas_load(&xas);
+       if (entry)
+               order = xas_get_order(&xas);
        rcu_read_unlock();
 
        return order;