Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

idr: Return the deleted entry from idr_remove

It is a relatively common idiom (8 instances) to first look up an IDR
entry, and then remove it from the tree if it is found, possibly doing
further operations upon the entry afterwards. If we change idr_remove()
to return the removed object, all of these users can save themselves a
walk of the IDR tree.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>

+15 -29
+2 -3
drivers/atm/nicstar.c
··· 1980 1980 card->lbfqc = ns_stat_lfbqc_get(stat); 1981 1981 1982 1982 id = le32_to_cpu(rsqe->buffer_handle); 1983 - skb = idr_find(&card->idr, id); 1983 + skb = idr_remove(&card->idr, id); 1984 1984 if (!skb) { 1985 1985 RXPRINTK(KERN_ERR 1986 - "nicstar%d: idr_find() failed!\n", card->index); 1986 + "nicstar%d: skb not found!\n", card->index); 1987 1987 return; 1988 1988 } 1989 - idr_remove(&card->idr, id); 1990 1989 dma_sync_single_for_cpu(&card->pcidev->dev, 1991 1990 NS_PRV_DMA(skb), 1992 1991 (NS_PRV_BUFTYPE(skb) == BUF_SM
+2 -4
drivers/block/drbd/drbd_main.c
··· 2915 2915 idr_remove(&connection->peer_devices, vnr); 2916 2916 out_idr_remove_from_resource: 2917 2917 for_each_connection(connection, resource) { 2918 - peer_device = idr_find(&connection->peer_devices, vnr); 2919 - if (peer_device) { 2920 - idr_remove(&connection->peer_devices, vnr); 2918 + peer_device = idr_remove(&connection->peer_devices, vnr); 2919 + if (peer_device) 2921 2920 kref_put(&connection->kref, drbd_destroy_connection); 2922 - } 2923 2921 } 2924 2922 for_each_peer_device_safe(peer_device, tmp_peer_device, device) { 2925 2923 list_del(&peer_device->peer_devices);
+1 -2
drivers/firewire/core-cdev.c
··· 1307 1307 */ 1308 1308 if (r->todo == ISO_RES_REALLOC && !success && 1309 1309 !client->in_shutdown && 1310 - idr_find(&client->resource_idr, r->resource.handle)) { 1311 - idr_remove(&client->resource_idr, r->resource.handle); 1310 + idr_remove(&client->resource_idr, r->resource.handle)) { 1312 1311 client_put(client); 1313 1312 free = true; 1314 1313 }
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
··· 70 70 struct amdgpu_bo_list *list; 71 71 72 72 mutex_lock(&fpriv->bo_list_lock); 73 - list = idr_find(&fpriv->bo_list_handles, id); 73 + list = idr_remove(&fpriv->bo_list_handles, id); 74 74 if (list) { 75 + /* Another user may have a reference to this list still */ 75 76 mutex_lock(&list->lock); 76 - idr_remove(&fpriv->bo_list_handles, id); 77 77 mutex_unlock(&list->lock); 78 78 amdgpu_bo_list_free(list); 79 79 }
+3 -7
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
··· 135 135 struct amdgpu_ctx *ctx; 136 136 137 137 mutex_lock(&mgr->lock); 138 - ctx = idr_find(&mgr->ctx_handles, id); 139 - if (ctx) { 140 - idr_remove(&mgr->ctx_handles, id); 138 + ctx = idr_remove(&mgr->ctx_handles, id); 139 + if (ctx) 141 140 kref_put(&ctx->refcount, amdgpu_ctx_do_release); 142 - mutex_unlock(&mgr->lock); 143 - return 0; 144 - } 145 141 mutex_unlock(&mgr->lock); 146 - return -EINVAL; 142 + return ctx ? 0 : -EINVAL; 147 143 } 148 144 149 145 static int amdgpu_ctx_query(struct amdgpu_device *adev,
+1 -3
drivers/net/wireless/marvell/mwifiex/txrx.c
··· 346 346 return; 347 347 348 348 spin_lock_irqsave(&priv->ack_status_lock, flags); 349 - ack_skb = idr_find(&priv->ack_status_frames, tx_status->tx_token_id); 350 - if (ack_skb) 351 - idr_remove(&priv->ack_status_frames, tx_status->tx_token_id); 349 + ack_skb = idr_remove(&priv->ack_status_frames, tx_status->tx_token_id); 352 350 spin_unlock_irqrestore(&priv->ack_status_lock, flags); 353 351 354 352 if (ack_skb) {
+1 -3
drivers/target/target_core_user.c
··· 642 642 WARN_ON(tcmu_hdr_get_op(entry->hdr.len_op) != TCMU_OP_CMD); 643 643 644 644 spin_lock(&udev->commands_lock); 645 - cmd = idr_find(&udev->commands, entry->hdr.cmd_id); 646 - if (cmd) 647 - idr_remove(&udev->commands, cmd->cmd_id); 645 + cmd = idr_remove(&udev->commands, entry->hdr.cmd_id); 648 646 spin_unlock(&udev->commands_lock); 649 647 650 648 if (!cmd) {
+2 -2
include/linux/idr.h
··· 88 88 void *idr_replace(struct idr *, void *, int id); 89 89 void idr_destroy(struct idr *); 90 90 91 - static inline void idr_remove(struct idr *idr, int id) 91 + static inline void *idr_remove(struct idr *idr, int id) 92 92 { 93 - radix_tree_delete(&idr->idr_rt, id); 93 + return radix_tree_delete_item(&idr->idr_rt, id, NULL); 94 94 } 95 95 96 96 static inline void idr_init(struct idr *idr)
+1 -3
net/mac80211/status.c
··· 462 462 unsigned long flags; 463 463 464 464 spin_lock_irqsave(&local->ack_status_lock, flags); 465 - skb = idr_find(&local->ack_status_frames, info->ack_frame_id); 466 - if (skb) 467 - idr_remove(&local->ack_status_frames, info->ack_frame_id); 465 + skb = idr_remove(&local->ack_status_frames, info->ack_frame_id); 468 466 spin_unlock_irqrestore(&local->ack_status_lock, flags); 469 467 470 468 if (!skb)