Skip to content

Commit 04dafdd

Browse files
RichardWeiYangakpm00
authored andcommitted
maple_tree: print empty for an empty tree on mt_dump()
Patch series "refine storing null", v5. When overwriting the whole range with NULL, current behavior is not correct. An empty tree is represented by having the tree point to NULL directly. An empty tree indicates the entire range (0-ULONG_MAX) is NULL. A store operation into an existing node that causes 0 - ULONG_MAX to be equal to NULL may not be restored to an empty state - a node is used to store the single range instead. This is wasteful and different from the initial setup of the tree. Once the tree is using a single node to store 0 - ULONG_MAX, problems may arise when storing more values into a tree with the unexpected state of 0 - ULONG being a single range in a node. User visible issues may mean a corrupt tree and incorrect storage of information within the tree. This would be limited to users who create and then empty a tree by overwriting all values, then try to store more NULLs into the empty tree. I cannot come up with an example of any user doing this (users usually destroy the tree and generally don't keep trying to store NULLs over NULLs), but patch 4/5 "maple_tree: refine mas_store_root() on storing NULL" should be backported just in case. This patch (of 5): Currently for an empty tree, it would print: maple_tree(0x7ffcd02c6ee0) flags 1, height 0 root (nil) 0: (nil) This is a little misleading. Let's print (empty) for an empty tree. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Wei Yang <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Sidhartha Kumar <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8e1817b commit 04dafdd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/maple_tree.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7273,10 +7273,12 @@ void mt_dump(const struct maple_tree *mt, enum mt_dump_format format)
72737273

72747274
pr_info("maple_tree(" PTR_FMT ") flags %X, height %u root " PTR_FMT "\n",
72757275
mt, mt->ma_flags, mt_height(mt), entry);
7276-
if (!xa_is_node(entry))
7277-
mt_dump_entry(entry, 0, 0, 0, format);
7278-
else if (entry)
7276+
if (xa_is_node(entry))
72797277
mt_dump_node(mt, entry, 0, mt_node_max(entry), 0, format);
7278+
else if (entry)
7279+
mt_dump_entry(entry, 0, 0, 0, format);
7280+
else
7281+
pr_info("(empty)\n");
72807282
}
72817283
EXPORT_SYMBOL_GPL(mt_dump);
72827284

0 commit comments

Comments
 (0)