Unverified Commit a391e89b authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files
parents 78361327 901dbb48
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ struct nvkm_client {

	struct nvkm_client_notify *notify[32];
	struct rb_root objroot;
	spinlock_t obj_lock;

	bool super;
	void *data;
+1 −0
Original line number Diff line number Diff line
@@ -300,6 +300,7 @@ nvkm_client_new(const char *name, u64 device, const char *cfg,
	client->device = device;
	client->debug = nvkm_dbgopt(dbg, "CLIENT");
	client->objroot = RB_ROOT;
	spin_lock_init(&client->obj_lock);
	client->ntfy = ntfy;
	INIT_LIST_HEAD(&client->umem);
	spin_lock_init(&client->lock);
+20 −6
Original line number Diff line number Diff line
@@ -30,8 +30,10 @@ nvkm_object_search(struct nvkm_client *client, u64 handle,
		   const struct nvkm_object_func *func)
{
	struct nvkm_object *object;
	unsigned long flags;

	if (handle) {
		spin_lock_irqsave(&client->obj_lock, flags);
		struct rb_node *node = client->objroot.rb_node;
		while (node) {
			object = rb_entry(node, typeof(*object), node);
@@ -40,9 +42,12 @@ nvkm_object_search(struct nvkm_client *client, u64 handle,
			else
			if (handle > object->object)
				node = node->rb_right;
			else
			else {
				spin_unlock_irqrestore(&client->obj_lock, flags);
				goto done;
			}
		}
		spin_unlock_irqrestore(&client->obj_lock, flags);
		return ERR_PTR(-ENOENT);
	} else {
		object = &client->object;
@@ -57,30 +62,39 @@ nvkm_object_search(struct nvkm_client *client, u64 handle,
void
nvkm_object_remove(struct nvkm_object *object)
{
	unsigned long flags;

	spin_lock_irqsave(&object->client->obj_lock, flags);
	if (!RB_EMPTY_NODE(&object->node))
		rb_erase(&object->node, &object->client->objroot);
	spin_unlock_irqrestore(&object->client->obj_lock, flags);
}

bool
nvkm_object_insert(struct nvkm_object *object)
{
	struct rb_node **ptr = &object->client->objroot.rb_node;
	struct rb_node **ptr;
	struct rb_node *parent = NULL;
	unsigned long flags;

	spin_lock_irqsave(&object->client->obj_lock, flags);
	ptr = &object->client->objroot.rb_node;
	while (*ptr) {
		struct nvkm_object *this = rb_entry(*ptr, typeof(*this), node);
		parent = *ptr;
		if (object->object < this->object)
		if (object->object < this->object) {
			ptr = &parent->rb_left;
		else
		if (object->object > this->object)
		} else if (object->object > this->object) {
			ptr = &parent->rb_right;
		else
		} else {
			spin_unlock_irqrestore(&object->client->obj_lock, flags);
			return false;
		}
	}

	rb_link_node(&object->node, parent, ptr);
	rb_insert_color(&object->node, &object->client->objroot);
	spin_unlock_irqrestore(&object->client->obj_lock, flags);
	return true;
}