]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Convert debug code to use MT_WARN_ON()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 31 Aug 2022 19:55:15 +0000 (15:55 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 1 Sep 2022 20:14:18 +0000 (16:14 -0400)
Using MT_WARN_ON() allows for the removal of if statements before
logging.

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

index 6c30c2b5ce529dc7c1f54b59f93aa7bf98dd212c..8488db5276ca93c51c37daf9d0d9704c21843625 100644 (file)
@@ -5640,9 +5640,8 @@ void *mas_store(struct ma_state *mas, void *entry)
 
        trace_ma_write(__func__, mas, 0, entry);
 #ifdef CONFIG_DEBUG_MAPLE_TREE
-       if (mas->index > mas->last)
+       if (MT_WARN_ON(mas->tree, mas->index > mas->last))
                pr_err("Error %lu > %lu %p\n", mas->index, mas->last, entry);
-       MT_BUG_ON(mas->tree, mas->index > mas->last);
        if (mas->index > mas->last) {
                mas_set_err(mas, -EINVAL);
                return NULL;
@@ -6454,10 +6453,9 @@ unlock:
        if (likely(entry)) {
                *index = mas.last + 1;
 #ifdef CONFIG_DEBUG_MAPLE_TREE
-               if ((*index) && (*index) <= copy)
+               if (MT_WARN_ON(mt, (*index) && ((*index) <= copy)))
                        pr_err("index not increased! %lx <= %lx\n",
                               *index, copy);
-               MT_BUG_ON(mt, (*index) && ((*index) <= copy));
 #endif
        }
 
@@ -6584,7 +6582,7 @@ static inline void *mas_first_entry(struct ma_state *mas, struct maple_node *mn,
        max = mas->max;
        mas->offset = 0;
        while (likely(!ma_is_leaf(mt))) {
-               MT_BUG_ON(mas->tree, mte_dead_node(mas->node));
+               MT_WARN_ON(mas->tree, mte_dead_node(mas->node));
                slots = ma_slots(mn, mt);
                pivots = ma_pivots(mn, mt);
                max = pivots[0];
@@ -6595,7 +6593,7 @@ static inline void *mas_first_entry(struct ma_state *mas, struct maple_node *mn,
                mn = mas_mn(mas);
                mt = mte_node_type(mas->node);
        }
-       MT_BUG_ON(mas->tree, mte_dead_node(mas->node));
+       MT_WARN_ON(mas->tree, mte_dead_node(mas->node));
 
        mas->max = max;
        slots = ma_slots(mn, mt);
@@ -6861,23 +6859,19 @@ static void mas_validate_gaps(struct ma_state *mas)
 
                        gap = gaps[i];
                        if (!entry) {
-                               if (gap != p_end - p_start + 1) {
+                               if (MT_WARN_ON(mas->tree,
+                                              gap != p_end - p_start + 1)) {
                                        pr_err("%p[%u] -> %p %lu != %lu - %lu + 1\n",
                                                mas_mn(mas), i,
                                                mas_get_slot(mas, i), gap,
                                                p_end, p_start);
-                                       mt_dump(mas->tree);
-
-                                       MT_BUG_ON(mas->tree,
-                                               gap != p_end - p_start + 1);
                                }
                        } else {
-                               if (gap > p_end - p_start + 1) {
+                               if (MT_WARN_ON(mas->tree,
+                                              gap > p_end - p_start + 1)) {
                                        pr_err("%p[%u] %lu >= %lu - %lu + 1 (%lu)\n",
                                        mas_mn(mas), i, gap, p_end, p_start,
                                        p_end - p_start + 1);
-                                       MT_BUG_ON(mas->tree,
-                                               gap > p_end - p_start + 1);
                                }
                        }
                }
@@ -6896,13 +6890,13 @@ counted:
 
        p_slot = mte_parent_slot(mas->node);
        p_mn = mte_parent(mte);
-       MT_BUG_ON(mas->tree, max_gap > mas->max);
+       MT_WARN_ON(mas->tree, max_gap > mas->max);
        if (ma_gaps(p_mn, mas_parent_enum(mas, mte))[p_slot] != max_gap) {
                pr_err("gap %p[%u] != %lu\n", p_mn, p_slot, max_gap);
                mt_dump(mas->tree);
        }
 
-       MT_BUG_ON(mas->tree,
+       MT_WARN_ON(mas->tree,
                  ma_gaps(p_mn, mas_parent_enum(mas, mte))[p_slot] != max_gap);
 }
 
@@ -6920,7 +6914,7 @@ static void mas_validate_parent_slot(struct ma_state *mas)
 
        parent = mte_parent(mas->node);
        slots = ma_slots(parent, p_type);
-       MT_BUG_ON(mas->tree, mas_mn(mas) == parent);
+       MT_WARN_ON(mas->tree, mas_mn(mas) == parent);
 
        /* Check prev/next parent slot for duplicate node entry */
 
@@ -6930,11 +6924,11 @@ static void mas_validate_parent_slot(struct ma_state *mas)
                        if (node != mas->node)
                                pr_err("parent %p[%u] does not have %p\n",
                                        parent, i, mas_mn(mas));
-                       MT_BUG_ON(mas->tree, node != mas->node);
+                       MT_WARN_ON(mas->tree, node != mas->node);
                } else if (node == mas->node) {
                        pr_err("Invalid child %p at parent %p[%u] p_slot %u\n",
                               mas_mn(mas), parent, i, p_slot);
-                       MT_BUG_ON(mas->tree, node == mas->node);
+                       MT_WARN_ON(mas->tree, node == mas->node);
                }
        }
 }
@@ -6958,19 +6952,16 @@ static void mas_validate_child_slot(struct ma_state *mas)
                if (!child)
                        break;
 
-               if (mte_parent_slot(child) != i) {
+               if (MT_WARN_ON(mas->tree, mte_parent_slot(child) != i))
                        pr_err("Slot error at %p[%u]: child %p has pslot %u\n",
                               mas_mn(mas), i, mte_to_node(child),
                               mte_parent_slot(child));
-                       MT_BUG_ON(mas->tree, 1);
-               }
 
-               if (mte_parent(child) != mte_to_node(mas->node)) {
+               if (MT_WARN_ON(mas->tree,
+                              mte_parent(child) != mte_to_node(mas->node)))
                        pr_err("child %p has parent %p not %p\n",
                               mte_to_node(child), mte_parent(child),
                               mte_to_node(mas->node));
-                       MT_BUG_ON(mas->tree, 1);
-               }
        }
 }
 
@@ -7004,24 +6995,24 @@ static void mas_validate_limits(struct ma_state *mas)
                                pr_err("%p[%u] cannot be null\n",
                                       mas_mn(mas), i);
 
-                       MT_BUG_ON(mas->tree, !entry);
+                       MT_WARN_ON(mas->tree, !entry);
                }
 
                if (prev_piv > piv) {
                        pr_err("%p[%u] piv %lu < prev_piv %lu\n",
                                mas_mn(mas), i, piv, prev_piv);
-                       MT_BUG_ON(mas->tree, piv < prev_piv);
+                       MT_WARN_ON(mas->tree, piv < prev_piv);
                }
 
                if (piv < mas->min) {
                        pr_err("%p[%u] %lu < %lu\n", mas_mn(mas), i,
                                piv, mas->min);
-                       MT_BUG_ON(mas->tree, piv < mas->min);
+                       MT_WARN_ON(mas->tree, piv < mas->min);
                }
                if (piv > mas->max) {
                        pr_err("%p[%u] %lu > %lu\n", mas_mn(mas), i,
                                piv, mas->max);
-                       MT_BUG_ON(mas->tree, piv > mas->max);
+                       MT_WARN_ON(mas->tree, piv > mas->max);
                }
                prev_piv = piv;
                if (piv == mas->max)
@@ -7033,7 +7024,7 @@ static void mas_validate_limits(struct ma_state *mas)
                if (entry && (i != mt_slots[type] - 1)) {
                        pr_err("%p[%u] should not have entry %p\n", mas_mn(mas),
                               i, entry);
-                       MT_BUG_ON(mas->tree, entry != NULL);
+                       MT_WARN_ON(mas->tree, entry != NULL);
                }
 
                if (i < mt_pivots[type]) {
@@ -7044,7 +7035,7 @@ static void mas_validate_limits(struct ma_state *mas)
 
                        pr_err("%p[%u] should not have piv %lu\n",
                               mas_mn(mas), i, piv);
-                       MT_BUG_ON(mas->tree, i < mt_pivots[type] - 1);
+                       MT_WARN_ON(mas->tree, i < mt_pivots[type] - 1);
                }
        }
 }
@@ -7070,7 +7061,7 @@ static void mt_validate_nulls(struct maple_tree *mt)
                        pr_err("Sequential nulls end at %p[%u]\n",
                                mas_mn(&mas), offset);
                }
-               MT_BUG_ON(mt, !last && !entry);
+               MT_WARN_ON(mt, !last && !entry);
                last = entry;
                if (offset == mas_data_end(&mas)) {
                        mas_next_node(&mas, mas_mn(&mas), ULONG_MAX);
@@ -7103,17 +7094,17 @@ void mt_validate(struct maple_tree *mt)
 
        mas_first_entry(&mas, mas_mn(&mas), ULONG_MAX, mte_node_type(mas.node));
        while (!mas_is_none(&mas)) {
-               MT_BUG_ON(mas.tree, mte_dead_node(mas.node));
+               MT_WARN_ON(mas.tree, mte_dead_node(mas.node));
                if (!mte_is_root(mas.node)) {
                        end = mas_data_end(&mas);
-                       if ((end < mt_min_slot_count(mas.node)) &&
-                           (mas.max != ULONG_MAX)) {
+                       if (MT_WARN_ON(mas.tree,
+                                      (end < mt_min_slot_count(mas.node)) &&
+                                      (mas.max != ULONG_MAX))) {
                                pr_err("Invalid size %u of %p\n", end,
                                mas_mn(&mas));
-                               MT_BUG_ON(mas.tree, 1);
                        }
-
                }
+
                mas_validate_parent_slot(&mas);
                mas_validate_child_slot(&mas);
                mas_validate_limits(&mas);