@@ -30,8 +30,10 @@ nvkm_object_search(struct nvkm_client *client, u64 handle,
3030 const struct nvkm_object_func * func )
3131{
3232 struct nvkm_object * object ;
33+ unsigned long flags ;
3334
3435 if (handle ) {
36+ spin_lock_irqsave (& client -> obj_lock , flags );
3537 struct rb_node * node = client -> objroot .rb_node ;
3638 while (node ) {
3739 object = rb_entry (node , typeof (* object ), node );
@@ -40,9 +42,12 @@ nvkm_object_search(struct nvkm_client *client, u64 handle,
4042 else
4143 if (handle > object -> object )
4244 node = node -> rb_right ;
43- else
45+ else {
46+ spin_unlock_irqrestore (& client -> obj_lock , flags );
4447 goto done ;
48+ }
4549 }
50+ spin_unlock_irqrestore (& client -> obj_lock , flags );
4651 return ERR_PTR (- ENOENT );
4752 } else {
4853 object = & client -> object ;
@@ -57,30 +62,39 @@ nvkm_object_search(struct nvkm_client *client, u64 handle,
5762void
5863nvkm_object_remove (struct nvkm_object * object )
5964{
65+ unsigned long flags ;
66+
67+ spin_lock_irqsave (& object -> client -> obj_lock , flags );
6068 if (!RB_EMPTY_NODE (& object -> node ))
6169 rb_erase (& object -> node , & object -> client -> objroot );
70+ spin_unlock_irqrestore (& object -> client -> obj_lock , flags );
6271}
6372
6473bool
6574nvkm_object_insert (struct nvkm_object * object )
6675{
67- struct rb_node * * ptr = & object -> client -> objroot . rb_node ;
76+ struct rb_node * * ptr ;
6877 struct rb_node * parent = NULL ;
78+ unsigned long flags ;
6979
80+ spin_lock_irqsave (& object -> client -> obj_lock , flags );
81+ ptr = & object -> client -> objroot .rb_node ;
7082 while (* ptr ) {
7183 struct nvkm_object * this = rb_entry (* ptr , typeof (* this ), node );
7284 parent = * ptr ;
73- if (object -> object < this -> object )
85+ if (object -> object < this -> object ) {
7486 ptr = & parent -> rb_left ;
75- else
76- if (object -> object > this -> object )
87+ } else if (object -> object > this -> object ) {
7788 ptr = & parent -> rb_right ;
78- else
89+ } else {
90+ spin_unlock_irqrestore (& object -> client -> obj_lock , flags );
7991 return false;
92+ }
8093 }
8194
8295 rb_link_node (& object -> node , parent , ptr );
8396 rb_insert_color (& object -> node , & object -> client -> objroot );
97+ spin_unlock_irqrestore (& object -> client -> obj_lock , flags );
8498 return true;
8599}
86100
0 commit comments