aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <mawilcox@microsoft.com>2016-12-22 13:30:22 -0500
committerMatthew Wilcox <mawilcox@microsoft.com>2017-02-13 21:44:03 -0500
commitd3e709e63e97e5f3f129b639991cfe266da60bae (patch)
tree78647f4029b9e83087fefa19144a689f6909f8d2
parent8ac04868315c6ffcb2c5a5ad9cd5cec61cad3576 (diff)
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>
-rw-r--r--drivers/atm/nicstar.c5
-rw-r--r--drivers/block/drbd/drbd_main.c6
-rw-r--r--drivers/firewire/core-cdev.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c10
-rw-r--r--drivers/net/wireless/marvell/mwifiex/txrx.c4
-rw-r--r--drivers/target/target_core_user.c4
-rw-r--r--include/linux/idr.h4
-rw-r--r--net/mac80211/status.c4
9 files changed, 15 insertions, 29 deletions
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index cb28579e8a94..d879f3bca107 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -1980,13 +1980,12 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
1980 card->lbfqc = ns_stat_lfbqc_get(stat); 1980 card->lbfqc = ns_stat_lfbqc_get(stat);
1981 1981
1982 id = le32_to_cpu(rsqe->buffer_handle); 1982 id = le32_to_cpu(rsqe->buffer_handle);
1983 skb = idr_find(&card->idr, id); 1983 skb = idr_remove(&card->idr, id);
1984 if (!skb) { 1984 if (!skb) {
1985 RXPRINTK(KERN_ERR 1985 RXPRINTK(KERN_ERR
1986 "nicstar%d: idr_find() failed!\n", card->index); 1986 "nicstar%d: skb not found!\n", card->index);
1987 return; 1987 return;
1988 } 1988 }
1989 idr_remove(&card->idr, id);
1990 dma_sync_single_for_cpu(&card->pcidev->dev, 1989 dma_sync_single_for_cpu(&card->pcidev->dev,
1991 NS_PRV_DMA(skb), 1990 NS_PRV_DMA(skb),
1992 (NS_PRV_BUFTYPE(skb) == BUF_SM 1991 (NS_PRV_BUFTYPE(skb) == BUF_SM
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 83482721bc01..6bb3b80e7e51 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -2915,11 +2915,9 @@ out_idr_remove_vol:
2915 idr_remove(&connection->peer_devices, vnr); 2915 idr_remove(&connection->peer_devices, vnr);
2916out_idr_remove_from_resource: 2916out_idr_remove_from_resource:
2917 for_each_connection(connection, resource) { 2917 for_each_connection(connection, resource) {
2918 peer_device = idr_find(&connection->peer_devices, vnr); 2918 peer_device = idr_remove(&connection->peer_devices, vnr);
2919 if (peer_device) { 2919 if (peer_device)
2920 idr_remove(&connection->peer_devices, vnr);
2921 kref_put(&connection->kref, drbd_destroy_connection); 2920 kref_put(&connection->kref, drbd_destroy_connection);
2922 }
2923 } 2921 }
2924 for_each_peer_device_safe(peer_device, tmp_peer_device, device) { 2922 for_each_peer_device_safe(peer_device, tmp_peer_device, device) {
2925 list_del(&peer_device->peer_devices); 2923 list_del(&peer_device->peer_devices);
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index aee149bdf4c0..a301fcf46e88 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1307,8 +1307,7 @@ static void iso_resource_work(struct work_struct *work)
1307 */ 1307 */
1308 if (r->todo == ISO_RES_REALLOC && !success && 1308 if (r->todo == ISO_RES_REALLOC && !success &&
1309 !client->in_shutdown && 1309 !client->in_shutdown &&
1310 idr_find(&client->resource_idr, r->resource.handle)) { 1310 idr_remove(&client->resource_idr, r->resource.handle)) {
1311 idr_remove(&client->resource_idr, r->resource.handle);
1312 client_put(client); 1311 client_put(client);
1313 free = true; 1312 free = true;
1314 } 1313 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index c02db01f6583..0218cea6be4d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -70,10 +70,10 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
70 struct amdgpu_bo_list *list; 70 struct amdgpu_bo_list *list;
71 71
72 mutex_lock(&fpriv->bo_list_lock); 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 if (list) { 74 if (list) {
75 /* Another user may have a reference to this list still */
75 mutex_lock(&list->lock); 76 mutex_lock(&list->lock);
76 idr_remove(&fpriv->bo_list_handles, id);
77 mutex_unlock(&list->lock); 77 mutex_unlock(&list->lock);
78 amdgpu_bo_list_free(list); 78 amdgpu_bo_list_free(list);
79 } 79 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 400c66ba4c6b..cf0500671353 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -135,15 +135,11 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
135 struct amdgpu_ctx *ctx; 135 struct amdgpu_ctx *ctx;
136 136
137 mutex_lock(&mgr->lock); 137 mutex_lock(&mgr->lock);
138 ctx = idr_find(&mgr->ctx_handles, id); 138 ctx = idr_remove(&mgr->ctx_handles, id);
139 if (ctx) { 139 if (ctx)
140 idr_remove(&mgr->ctx_handles, id);
141 kref_put(&ctx->refcount, amdgpu_ctx_do_release); 140 kref_put(&ctx->refcount, amdgpu_ctx_do_release);
142 mutex_unlock(&mgr->lock);
143 return 0;
144 }
145 mutex_unlock(&mgr->lock); 141 mutex_unlock(&mgr->lock);
146 return -EINVAL; 142 return ctx ? 0 : -EINVAL;
147} 143}
148 144
149static int amdgpu_ctx_query(struct amdgpu_device *adev, 145static int amdgpu_ctx_query(struct amdgpu_device *adev,
diff --git a/drivers/net/wireless/marvell/mwifiex/txrx.c b/drivers/net/wireless/marvell/mwifiex/txrx.c
index abdd0cf710bf..fac28bd8fbee 100644
--- a/drivers/net/wireless/marvell/mwifiex/txrx.c
+++ b/drivers/net/wireless/marvell/mwifiex/txrx.c
@@ -346,9 +346,7 @@ void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
346 return; 346 return;
347 347
348 spin_lock_irqsave(&priv->ack_status_lock, flags); 348 spin_lock_irqsave(&priv->ack_status_lock, flags);
349 ack_skb = idr_find(&priv->ack_status_frames, tx_status->tx_token_id); 349 ack_skb = idr_remove(&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);
352 spin_unlock_irqrestore(&priv->ack_status_lock, flags); 350 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
353 351
354 if (ack_skb) { 352 if (ack_skb) {
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 8041710b6972..18f0ec2e1f9c 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -642,9 +642,7 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev)
642 WARN_ON(tcmu_hdr_get_op(entry->hdr.len_op) != TCMU_OP_CMD); 642 WARN_ON(tcmu_hdr_get_op(entry->hdr.len_op) != TCMU_OP_CMD);
643 643
644 spin_lock(&udev->commands_lock); 644 spin_lock(&udev->commands_lock);
645 cmd = idr_find(&udev->commands, entry->hdr.cmd_id); 645 cmd = idr_remove(&udev->commands, entry->hdr.cmd_id);
646 if (cmd)
647 idr_remove(&udev->commands, cmd->cmd_id);
648 spin_unlock(&udev->commands_lock); 646 spin_unlock(&udev->commands_lock);
649 647
650 if (!cmd) { 648 if (!cmd) {
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 2027c7aba50d..bf70b3ef0a07 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -88,9 +88,9 @@ void *idr_get_next(struct idr *, int *nextid);
88void *idr_replace(struct idr *, void *, int id); 88void *idr_replace(struct idr *, void *, int id);
89void idr_destroy(struct idr *); 89void idr_destroy(struct idr *);
90 90
91static inline void idr_remove(struct idr *idr, int id) 91static 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
96static inline void idr_init(struct idr *idr) 96static inline void idr_init(struct idr *idr)
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index ddf71c648cab..43dd3316d8a4 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -462,9 +462,7 @@ static void ieee80211_report_ack_skb(struct ieee80211_local *local,
462 unsigned long flags; 462 unsigned long flags;
463 463
464 spin_lock_irqsave(&local->ack_status_lock, flags); 464 spin_lock_irqsave(&local->ack_status_lock, flags);
465 skb = idr_find(&local->ack_status_frames, info->ack_frame_id); 465 skb = idr_remove(&local->ack_status_frames, info->ack_frame_id);
466 if (skb)
467 idr_remove(&local->ack_status_frames, info->ack_frame_id);
468 spin_unlock_irqrestore(&local->ack_status_lock, flags); 466 spin_unlock_irqrestore(&local->ack_status_lock, flags);
469 467
470 if (!skb) 468 if (!skb)