]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Return error on mte_pivots() out of range
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 2 Sep 2022 15:23:21 +0000 (11:23 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 2 Sep 2022 19:41:15 +0000 (15:41 -0400)
Rename mte_pivots() to mas_pivots() and pass through the ma_state to set
the error code to -EIO when the offset is out of range for the node
type.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index 9401136d77dc2533ef9bc13e9973379e89f9a53b..8645b9b867196cd37881bf91044e89c06fcded38 100644 (file)
@@ -662,22 +662,21 @@ static inline unsigned long *ma_gaps(struct maple_node *node,
 }
 
 /*
- * mte_pivot() - Get the pivot at @piv of the maple encoded node.
- * @mn: The maple encoded node.
+ * mas_pivot() - Get the pivot at @piv of the maple encoded node.
+ * @mas: The maple state.
  * @piv: The pivot.
  *
  * Return: the pivot at @piv of @mn.
  */
-static inline unsigned long mte_pivot(const struct maple_enode *mn,
-                                unsigned char piv)
+static inline unsigned long mas_pivot(struct ma_state *mas, unsigned char piv)
 {
-       struct maple_node *node = mte_to_node(mn);
+       struct maple_node *node = mas_mn(mas);
 
-       if (piv >= mt_pivots[piv]) {
-               WARN_ON(1);
+       if (WARN_ON(piv >= mt_pivots[piv])) {
+               mas_set_err(mas, -EIO);
                return 0;
        }
-       switch (mte_node_type(mn)) {
+       switch (mte_node_type(mas->node)) {
        case maple_arange_64:
                return node->ma64.pivot[piv];
        case maple_range_64:
@@ -5357,8 +5356,8 @@ static inline int mas_alloc(struct ma_state *mas, void *entry,
                        return xa_err(mas->node);
 
                if (!mas->index)
-                       return mte_pivot(mas->node, 0);
-               return mte_pivot(mas->node, 1);
+                       return mas_pivot(mas, 0);
+               return mas_pivot(mas, 1);
        }
 
        /* Must be walking a tree. */
@@ -5375,7 +5374,10 @@ static inline int mas_alloc(struct ma_state *mas, void *entry,
         */
        min = mas->min;
        if (mas->offset)
-               min = mte_pivot(mas->node, mas->offset - 1) + 1;
+               min = mas_pivot(mas, mas->offset - 1) + 1;
+
+       if (mas_is_err(mas))
+               return xa_err(mas->node);
 
        if (mas->index < min)
                mas->index = min;