radix-tree.c:__lookup_slot() dead code removal
Most of the code suggests that it is valid to insert a NULL item, possibly a zero item with pointer cast. However, in __lookup_slot() whether or not the slot is found seems to depend on the actual value of the item in one special case. But further on it doesn't make any difference so to remove some dead code:
lib/radix-tree.c +0 -3
@@ -319,9 +319,6 @@ static inline void **__lookup_slot(strucif (index >radix_tree_maxindex (height))return NULL ; -if (height ==0 && root->rnode) -return (void **)&root->rnode; - shift = (height-1 ) *RADIX_TREE_MAP_SHIFT ; slot = &root->rnode;
Signature · 1 line
Frank
Fengguang Wu
Acked-bylib/radix-tree.c static inline void **__lookup_slot(struc · line 323
Quoted 11 lines · Frank van Maarseveen
lib/radix-tree.c +0
-3@@ -319,9 +319,6 @@ static inline void **__lookup_slot(strucif (index >radix_tree_maxindex (height))return NULL ; -if (height ==0 && root->rnode) -return (void **)&root->rnode; - shift = (height-1 ) *RADIX_TREE_MAP_SHIFT ; slot = &root->rnode;
Quoted 9 lines · Frank van Maarseveen
Most of the code suggests that it is valid to insert a NULL item, possibly a zero item with pointer cast. However, in
__lookup_slot()whether or not the slot is found seems to depend on the actual value of the item in one special case. But further on it doesn't make any difference so to remove some dead code:
lib/radix-tree.c static inline void **__lookup_slot(struc · line 323
Quoted 8 lines
lib/radix-tree.c +0
-3@@ -319,9 +319,6 @@ static inline void **__lookup_slot(strucif (index >radix_tree_maxindex (height))return NULL ; -if (height ==0 && root->rnode) -return (void **)&root->rnode; - shift = (height-1 ) *RADIX_TREE_MAP_SHIFT ; slot = &root->rnode;
I would say it is not valid to insert a NULL item (because NULL means an unsuccessful lookup, you may as well just delete the item).
Also, I don't see how this is dead code anyway. height == 0 radix-trees are a special case and do not have a radix_tree_node at ->rnode.
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 23 lines · Nick Piggin
Quoted 9 lines · Frank van Maarseveen
Most of the code suggests that it is valid to insert a NULL item, possibly a zero item with pointer cast. However, in
__lookup_slot()whether or not the slot is found seems to depend on the actual value of the item in one special case. But further on it doesn't make any difference so to remove some dead code:lib/radix-tree.c static inline void **__lookup_slot(struc · line 323
Quoted 8 lines
lib/radix-tree.c +0
-3@@ -319,9 +319,6 @@ static inline void **__lookup_slot(strucif (index >radix_tree_maxindex (height))return NULL ; -if (height ==0 && root->rnode) -return (void **)&root->rnode; - shift = (height-1 ) *RADIX_TREE_MAP_SHIFT ; slot = &root->rnode;I would say it is not valid to insert a NULL item (because NULL means an unsuccessful lookup, you may as well just delete the item).
Quoted 3 lines
Also, I don't see how this is dead code anyway. height == 0 radix-trees are a special case and do not have a
radix_tree_nodeat ->rnode.
Sorry.
For linux-2.6.19 it was redundant code:
if (height == 0 && root->rnode)
return (void **)&root->rnode;
shift = (height-1) * RADIX_TREE_MAP_SHIFT;
slot = &root->rnode;
while (height > 0) {
......
}
return (void **)slot;I just find out it is no longer the case for -mm: the function has been heavily reworked.
So, the patch is no longer valid.
Fengguang Wu