Skip to content

Commit 6a3c029

Browse files
committed
Get rid of the cdev handle refcount.
We only create one VM cdev object per GEM object, and the VM object destructor runs only once all of its references are gone.
1 parent e2ada6d commit 6a3c029

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

sys/compat/linuxkpi/common/src/linux_compat.c

+11-17
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ linux_cdev_pager_populate(vm_object_t vm_obj, vm_pindex_t pidx, int fault_type,
737737
}
738738

739739
struct list_head lcdev_handle_list;
740+
740741
struct lcdev_handle_ref {
741-
volatile int refcnt;
742742
void *handle;
743743
void *data;
744744
struct list_head list;
@@ -754,23 +754,20 @@ linux_cdev_handle_insert(void *handle, void *data, int size)
754754
rw_rlock(&linux_global_rw);
755755
list_for_each(h, &lcdev_handle_list) {
756756
r = __containerof(h, struct lcdev_handle_ref, list);
757-
if (r->handle == handle)
758-
break;
759-
}
760-
if (r && r->handle == handle) {
761-
atomic_add_int(&r->refcnt, 1);
762-
rw_runlock(&linux_global_rw);
763-
return;
757+
if (r->handle == handle) {
758+
rw_runlock(&linux_global_rw);
759+
return;
760+
}
764761
}
765762
rw_runlock(&linux_global_rw);
766763
r = lkpi_malloc(sizeof(struct lcdev_handle_ref), M_KMALLOC, M_WAITOK);
767-
r->refcnt = 1;
768764
r->handle = handle;
769765
datap = lkpi_malloc(size, M_KMALLOC, M_WAITOK);
770766
memcpy(datap, data, size);
771767
r->data = datap;
772-
INIT_LIST_HEAD(&r->list);
768+
INIT_LIST_HEAD(&r->list); /* XXX why _HEAD? */
773769
rw_wlock(&linux_global_rw);
770+
/* XXX need to re-lookup */
774771
list_add_tail(&r->list, &lcdev_handle_list);
775772
rw_wunlock(&linux_global_rw);
776773
}
@@ -788,13 +785,10 @@ linux_cdev_handle_remove(void *handle)
788785
break;
789786
}
790787
MPASS (r && r->handle == handle);
791-
if (atomic_fetchadd_int(&r->refcnt, -1) == 0) {
792-
list_del(&r->list);
793-
rw_wunlock(&linux_global_rw);
794-
lkpi_free(r->data, M_KMALLOC);
795-
lkpi_free(r, M_KMALLOC);
796-
} else
797-
rw_wunlock(&linux_global_rw);
788+
list_del(&r->list);
789+
rw_wunlock(&linux_global_rw);
790+
lkpi_free(r->data, M_KMALLOC);
791+
lkpi_free(r, M_KMALLOC);
798792
}
799793

800794
static void *

0 commit comments

Comments
 (0)