summaryrefslogtreecommitdiffstats
path: root/include/drm
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2018-09-26 15:57:46 +0200
committerThomas Hellstrom <thellstrom@vmware.com>2018-09-28 08:55:10 +0200
commit24dc64c1ba5c3ef0463d59fef6df09336754188d (patch)
tree90b59c211d1d1375d2cd98b657aa400dd964b599 /include/drm
parente14c02e6b6990e9f6ee18a214a22ac26bae1b25e (diff)
downloadlinux-24dc64c1ba5c3ef0463d59fef6df09336754188d.tar.bz2
drm/ttm: Export ttm_bo_get_unless_zero()
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>
Diffstat (limited to 'include/drm')
-rw-r--r--include/drm/ttm/ttm_bo_api.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 8c19470785e2..3fc4854dce49 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -313,6 +313,24 @@ ttm_bo_reference(struct ttm_buffer_object *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.
*
* @bo: The buffer object.