]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm/ttm: Export ttm_bo_get_unless_zero()
authorThomas Hellstrom <thellstrom@vmware.com>
Wed, 26 Sep 2018 13:57:46 +0000 (15:57 +0200)
committerThomas Hellstrom <thellstrom@vmware.com>
Fri, 28 Sep 2018 06:55:10 +0000 (08:55 +0200)
Export ttm_bo_get_unless_zero() 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>
Reviewed-by: Christian König <christian.koenig@amd.com>
drivers/gpu/drm/ttm/ttm_bo_vm.c
include/drm/ttm/ttm_bo_api.h

index 6fe91c1b692d6fd547fcfff08b1633c229e77b0a..a1d977fbade5502c8edad616e537702d75dc1673 100644 (file)
@@ -409,8 +409,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_get_unless_zero(bo);
        }
 
        drm_vma_offset_unlock_lookup(&bdev->vma_manager);
index 8c19470785e2858e4796a4df8a234ebee900d4b8..3fc4854dce491266cec574c2b0b09f51972b64b7 100644 (file)
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
        return bo;
 }
 
+/**
+ * ttm_bo_get_unless_zero - 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_get_unless_zero(struct ttm_buffer_object *bo)
+{
+       if (!kref_get_unless_zero(&bo->kref))
+               return NULL;
+       return bo;
+}
+
 /**
  * ttm_bo_wait - wait for buffer idle.
  *