Skip to contentSkip to conversation

maple_tree: not necessary to filter MAPLE_PARENT_ROOT since it is not a root

PATCH In review Wei Yang 2 participants 4 messages Nov 13, 2022 – Nov 17, 2022

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 maple_tree: not necessary to filter MAPLE_PARENT_ROOT since it is not a root

Root node is return at the beginning, so we are sure bit 0 is not set.

CC Liam R. Howlett <[email protected]>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/maple_tree.c +1 -1
index 9aad98c24f3e..f8c4755e7c75 100644
@@ -436,7 +436,7 @@ enum maple_type mte_parent_enum(struct maple_enode *p_enode,
 		return 0; /* Validated in the caller. */
 
 	p_type &= MAPLE_NODE_MASK;
-	p_type = p_type & ~(MAPLE_PARENT_ROOT | mte_parent_slot_mask(p_type));
+	p_type = p_type & ~mte_parent_slot_mask(p_type);
 
 	switch (p_type) {
 	case MAPLE_PARENT_RANGE64: /* or MAPLE_PARENT_ARANGE64 */
Signature · 1 line
2.33.1
#1 lore raw
Quoted 13 lines · Wei Yang

Root node is return at the beginning, so we are sure bit 0 is not set.

CC Liam R. Howlett <[email protected]>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/maple_tree.c +0 -0
index 9aad98c24f3e..f8c4755e7c75 100644

lib/maple_tree.c enum maple_type mte_parent_enum(struct maple_enode *p_enode, · line 439

Quoted 5 lines
lib/maple_tree.c +1 -1
@@ -436,7 +436,7 @@ enum maple_type mte_parent_enum(struct maple_enode *p_enode,
 		return 0; /* Validated in the caller. */
 
 	p_type &= MAPLE_NODE_MASK;
-	p_type = p_type & ~(MAPLE_PARENT_ROOT | mte_parent_slot_mask(p_type));
+	p_type = p_type & ~mte_parent_slot_mask(p_type);

I think there is a larger cleanup that can be done here. It looks like mte_parent_enum() is called from one location and that location is a wrapper.

The check for the root bit should also probably trigger a WARN_ON() and still return 0. I don't think the callers are doing enough to validate it - although they should never reach this function with a root node. And, in fact, I am not doing enough in the test code since I didn't guard this correctly in the verification of the parent slot before calling this function.

Thanks for pointing this out. I will send out a patch to clean this up shortly.

Quoted 6 lines
lib/maple_tree.c +0 -0
 	switch (p_type) {
 	case MAPLE_PARENT_RANGE64: /* or MAPLE_PARENT_ARANGE64 */
Signature · 1 line
2.33.1
#2 lore raw
Quoted 31 lines · Liam R. Howlett
Quoted 13 lines · Wei Yang

Root node is return at the beginning, so we are sure bit 0 is not set.

CC Liam R. Howlett <[email protected]>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/maple_tree.c +0 -0
index 9aad98c24f3e..f8c4755e7c75 100644

lib/maple_tree.c enum maple_type mte_parent_enum(struct maple_enode *p_enode, · line 439

Quoted 5 lines
lib/maple_tree.c +1 -1
@@ -436,7 +436,7 @@ enum maple_type mte_parent_enum(struct maple_enode *p_enode,
 		return 0; /* Validated in the caller. */
 
 	p_type &= MAPLE_NODE_MASK;
-	p_type = p_type & ~(MAPLE_PARENT_ROOT | mte_parent_slot_mask(p_type));
+	p_type = p_type & ~mte_parent_slot_mask(p_type);

I think there is a larger cleanup that can be done here. It looks like mte_parent_enum() is called from one location and that location is a wrapper.

The check for the root bit should also probably trigger a WARN_ON() and still return 0. I don't think the callers are doing enough to validate it - although they should never reach this function with a root node. And, in fact, I am not doing enough in the test code since I didn't guard this correctly in the verification of the parent slot before calling this function.

Quoted 2 lines

Thanks for pointing this out. I will send out a patch to clean this up shortly.

On second thought, I will hold off for the 6.2 merge window for this to go upstream.

Thanks,
Liam

author
#3 lore raw
In reply to Liam Howlett
Quoted 31 lines · Liam Howlett
Quoted 13 lines · Wei Yang

Root node is return at the beginning, so we are sure bit 0 is not set.

CC Liam R. Howlett <[email protected]>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/maple_tree.c +0 -0
index 9aad98c24f3e..f8c4755e7c75 100644

lib/maple_tree.c enum maple_type mte_parent_enum(struct maple_enode *p_enode, · line 439

Quoted 5 lines
lib/maple_tree.c +1 -1
@@ -436,7 +436,7 @@ enum maple_type mte_parent_enum(struct maple_enode *p_enode,
 		return 0; /* Validated in the caller. */
 
 	p_type &= MAPLE_NODE_MASK;
-	p_type = p_type & ~(MAPLE_PARENT_ROOT | mte_parent_slot_mask(p_type));
+	p_type = p_type & ~mte_parent_slot_mask(p_type);

I think there is a larger cleanup that can be done here. It looks like mte_parent_enum() is called from one location and that location is a wrapper.

The check for the root bit should also probably trigger a WARN_ON() and still return 0. I don't think the callers are doing enough to validate it - although they should never reach this function with a root node. And, in fact, I am not doing enough in the test code since I didn't guard this correctly in the verification of the parent slot before calling this function.

Quoted 3 lines

Thanks for pointing this out. I will send out a patch to clean this up shortly.

Yep, look forward your cleanup.

While I have a question here. We get 4 types in maple_type, here we just return two of them. This means the other two is not possible to be parent node, right?

Quoted 6 lines
Quoted 6 lines
lib/maple_tree.c +0 -0
 	switch (p_type) {
 	case MAPLE_PARENT_RANGE64: /* or MAPLE_PARENT_ARANGE64 */
Signature · 1 line
2.33.1
Signature · 2 lines
Wei Yang
Help you, Help me