summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2018-09-18 10:51:54 +0200
committerThomas Hellstrom <thellstrom@vmware.com>2018-09-25 11:16:17 +0200
commit19e0663b3b89b5d6f2bd40a18646859df8f481c5 (patch)
tree8a391aabb2d24ef52fa6fff443378b136cea2877
parentcf50092355f7ed2e2997630edd68f8be725c89d4 (diff)
vmwgfx/ttm: Export ttm_bo_reference_unless_doomed()
Export ttm_bo_reference_unless_doomed() to be used when looking up buffer objects that are removed from the lookup structure in the destructor. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Sinclair Yeh <syeh@vmware.com>
-rw-r--r--ttm/ttm_bo_api.h18
-rw-r--r--ttm/ttm_bo_vm.c3
2 files changed, 19 insertions, 2 deletions
diff --git a/ttm/ttm_bo_api.h b/ttm/ttm_bo_api.h
index cc1ee49..e66cee4 100644
--- a/ttm/ttm_bo_api.h
+++ b/ttm/ttm_bo_api.h
@@ -285,6 +285,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
}
/**
+ * ttm_bo_reference_unless_doomed - reference a struct ttm_buffer_object unless
+ * its refcount has already reached zero.
+ * @bo: The buffer object.
+ *
+ * Used to reference a TTM buffer object in lookups where the object is removed
+ * from the lookup structure during the destructor and for RCU lookups.
+ *
+ * Returns: @bo if the referencing was successful, NULL otherwise.
+ */
+static inline __must_check struct ttm_buffer_object *
+ttm_bo_reference_unless_doomed(struct ttm_buffer_object *bo)
+{
+ if (!kref_get_unless_zero(&bo->kref))
+ return NULL;
+ return bo;
+}
+
+/**
* ttm_bo_wait - wait for buffer idle.
*
* @bo: The buffer object.
diff --git a/ttm/ttm_bo_vm.c b/ttm/ttm_bo_vm.c
index f483b72..266646e 100644
--- a/ttm/ttm_bo_vm.c
+++ b/ttm/ttm_bo_vm.c
@@ -335,8 +335,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages);
if (likely(node)) {
bo = container_of(node, struct ttm_buffer_object, vma_node);
- if (!kref_get_unless_zero(&bo->kref))
- bo = NULL;
+ bo = ttm_bo_reference_unless_doomed(bo);
}
drm_vma_offset_unlock_lookup(&bdev->vma_manager);