aboutsummaryrefslogtreecommitdiffstats
path: root/lib/radix-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/radix-tree.c')
-rw-r--r--lib/radix-tree.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index bd4a8dfdf0b8..d832117e7d94 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1337,15 +1337,18 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1337} 1337}
1338 1338
1339/** 1339/**
1340 * radix_tree_delete - delete an item from a radix tree 1340 * radix_tree_delete_item - delete an item from a radix tree
1341 * @root: radix tree root 1341 * @root: radix tree root
1342 * @index: index key 1342 * @index: index key
1343 * @item: expected item
1343 * 1344 *
1344 * Remove the item at @index from the radix tree rooted at @root. 1345 * Remove @item at @index from the radix tree rooted at @root.
1345 * 1346 *
1346 * Returns the address of the deleted item, or NULL if it was not present. 1347 * Returns the address of the deleted item, or NULL if it was not present
1348 * or the entry at the given @index was not @item.
1347 */ 1349 */
1348void *radix_tree_delete(struct radix_tree_root *root, unsigned long index) 1350void *radix_tree_delete_item(struct radix_tree_root *root,
1351 unsigned long index, void *item)
1349{ 1352{
1350 struct radix_tree_node *node = NULL; 1353 struct radix_tree_node *node = NULL;
1351 struct radix_tree_node *slot = NULL; 1354 struct radix_tree_node *slot = NULL;
@@ -1380,6 +1383,11 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1380 if (slot == NULL) 1383 if (slot == NULL)
1381 goto out; 1384 goto out;
1382 1385
1386 if (item && slot != item) {
1387 slot = NULL;
1388 goto out;
1389 }
1390
1383 /* 1391 /*
1384 * Clear all tags associated with the item to be deleted. 1392 * Clear all tags associated with the item to be deleted.
1385 * This way of doing it would be inefficient, but seldom is any set. 1393 * This way of doing it would be inefficient, but seldom is any set.
@@ -1424,6 +1432,21 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1424out: 1432out:
1425 return slot; 1433 return slot;
1426} 1434}
1435EXPORT_SYMBOL(radix_tree_delete_item);
1436
1437/**
1438 * radix_tree_delete - delete an item from a radix tree
1439 * @root: radix tree root
1440 * @index: index key
1441 *
1442 * Remove the item at @index from the radix tree rooted at @root.
1443 *
1444 * Returns the address of the deleted item, or NULL if it was not present.
1445 */
1446void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1447{
1448 return radix_tree_delete_item(root, index, NULL);
1449}
1427EXPORT_SYMBOL(radix_tree_delete); 1450EXPORT_SYMBOL(radix_tree_delete);
1428 1451
1429/** 1452/**