Skip to contentSkip to conversation

drm/ttm: Export ttm_bo_get_unless_zero()

PATCH Koenig, Christian 1 participant 1 message Sep 28, 2018

Subsystems (3)
lore
Share & tools
lore

Koenig, Christian

author Reviewed-by Sinclair Yeh
#0 lore raw

Am 28.09.2018 07:39 schrieb Thomas Hellstrom <[email protected]>:
Export ttm_bo_reference_unless_doomed() to be used when looking up buffer objects that are removed from the lookup structure in the destructor.

Reviewed-by Christian König <[email protected]>

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--
 include/drm/ttm/ttm_bo_api.h    | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +1 -2
index 6fe91c1b692d..a1d977fbade5 100644
@@ -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);
include/drm/ttm/ttm_bo_api.h +18 -0
index 8c19470785e2..3fc4854dce49 100644
@@ -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.
  *

--
2.19.0.rc1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel