<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="auto">
<div><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">Am 28.09.2018 07:39 schrieb Thomas Hellstrom <thellstrom@vmware.com>:<br type="attribution">
<blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><font size="2"><span style="font-size:11pt">
<div>Export ttm_bo_reference_unless_doomed() to be used when looking up buffer<br>
objects that are removed from the lookup structure in the destructor.<br>
<br>
Cc: Christian König <christian.koenig@amd.com><br>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com><br>
Reviewed-by: Sinclair Yeh <syeh@vmware.com><br>
</div>
</span></font></div>
</blockquote>
</div>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">Reviewed-by Christian König <christian.koenig@amd.com></div>
<div dir="auto"><br>
</div>
<div dir="auto">
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><font size="2"><span style="font-size:11pt">
<div>---<br>
 drivers/gpu/drm/ttm/ttm_bo_vm.c |  3 +--<br>
 include/drm/ttm/ttm_bo_api.h    | 18 ++++++++++++++++++<br>
 2 files changed, 19 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c<br>
index 6fe91c1b692d..a1d977fbade5 100644<br>
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c<br>
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c<br>
@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,<br>
         node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages);<br>
         if (likely(node)) {<!-- --><br>
                 bo = container_of(node, struct ttm_buffer_object, vma_node);<br>
-               if (!kref_get_unless_zero(&bo->kref))<br>
-                       bo = NULL;<br>
+               bo = ttm_bo_get_unless_zero(bo);<br>
         }<br>
 <br>
         drm_vma_offset_unlock_lookup(&bdev->vma_manager);<br>
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h<br>
index 8c19470785e2..3fc4854dce49 100644<br>
--- a/include/drm/ttm/ttm_bo_api.h<br>
+++ b/include/drm/ttm/ttm_bo_api.h<br>
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)<br>
         return bo;<br>
 }<br>
 <br>
+/**<br>
+ * ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless<br>
+ * its refcount has already reached zero.<br>
+ * @bo: The buffer object.<br>
+ *<br>
+ * Used to reference a TTM buffer object in lookups where the object is removed<br>
+ * from the lookup structure during the destructor and for RCU lookups.<br>
+ *<br>
+ * Returns: @bo if the referencing was successful, NULL otherwise.<br>
+ */<br>
+static inline __must_check struct ttm_buffer_object *<br>
+ttm_bo_get_unless_zero(struct ttm_buffer_object *bo)<br>
+{<!-- --><br>
+       if (!kref_get_unless_zero(&bo->kref))<br>
+               return NULL;<br>
+       return bo;<br>
+}<br>
+<br>
 /**<br>
  * ttm_bo_wait - wait for buffer idle.<br>
  *<br>
-- <br>
2.19.0.rc1<br>
<br>
</div>
</span></font></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</body>
</html>