Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3e709e6 authored by Matthew Wilcox's avatar Matthew Wilcox
Browse files

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: default avatarMatthew Wilcox <mawilcox@microsoft.com>
parent 8ac04868
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -1980,13 +1980,12 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
	card->lbfqc = ns_stat_lfbqc_get(stat);

	id = le32_to_cpu(rsqe->buffer_handle);
	skb = idr_find(&card->idr, id);
	skb = idr_remove(&card->idr, id);
	if (!skb) {
		RXPRINTK(KERN_ERR
			 "nicstar%d: idr_find() failed!\n", card->index);
			 "nicstar%d: skb not found!\n", card->index);
		return;
	}
	idr_remove(&card->idr, id);
	dma_sync_single_for_cpu(&card->pcidev->dev,
				NS_PRV_DMA(skb),
				(NS_PRV_BUFTYPE(skb) == BUF_SM
+2 −4
Original line number Diff line number Diff line
@@ -2915,12 +2915,10 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
	idr_remove(&connection->peer_devices, vnr);
out_idr_remove_from_resource:
	for_each_connection(connection, resource) {
		peer_device = idr_find(&connection->peer_devices, vnr);
		if (peer_device) {
			idr_remove(&connection->peer_devices, vnr);
		peer_device = idr_remove(&connection->peer_devices, vnr);
		if (peer_device)
			kref_put(&connection->kref, drbd_destroy_connection);
	}
	}
	for_each_peer_device_safe(peer_device, tmp_peer_device, device) {
		list_del(&peer_device->peer_devices);
		kfree(peer_device);
+1 −2
Original line number Diff line number Diff line
@@ -1307,8 +1307,7 @@ static void iso_resource_work(struct work_struct *work)
	 */
	if (r->todo == ISO_RES_REALLOC && !success &&
	    !client->in_shutdown &&
	    idr_find(&client->resource_idr, r->resource.handle)) {
		idr_remove(&client->resource_idr, r->resource.handle);
	    idr_remove(&client->resource_idr, r->resource.handle)) {
		client_put(client);
		free = true;
	}
+2 −2
Original line number Diff line number Diff line
@@ -70,10 +70,10 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
	struct amdgpu_bo_list *list;

	mutex_lock(&fpriv->bo_list_lock);
	list = idr_find(&fpriv->bo_list_handles, id);
	list = idr_remove(&fpriv->bo_list_handles, id);
	if (list) {
		/* Another user may have a reference to this list still */
		mutex_lock(&list->lock);
		idr_remove(&fpriv->bo_list_handles, id);
		mutex_unlock(&list->lock);
		amdgpu_bo_list_free(list);
	}
+3 −7
Original line number Diff line number Diff line
@@ -135,15 +135,11 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
	struct amdgpu_ctx *ctx;

	mutex_lock(&mgr->lock);
	ctx = idr_find(&mgr->ctx_handles, id);
	if (ctx) {
		idr_remove(&mgr->ctx_handles, id);
	ctx = idr_remove(&mgr->ctx_handles, id);
	if (ctx)
		kref_put(&ctx->refcount, amdgpu_ctx_do_release);
	mutex_unlock(&mgr->lock);
		return 0;
	}
	mutex_unlock(&mgr->lock);
	return -EINVAL;
	return ctx ? 0 : -EINVAL;
}

static int amdgpu_ctx_query(struct amdgpu_device *adev,
Loading