Skip to content

Commit 24dc64c

Browse files
committed
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>
1 parent e14c02e commit 24dc64c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

drivers/gpu/drm/ttm/ttm_bo_vm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
409409
node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages);
410410
if (likely(node)) {
411411
bo = container_of(node, struct ttm_buffer_object, vma_node);
412-
if (!kref_get_unless_zero(&bo->kref))
413-
bo = NULL;
412+
bo = ttm_bo_get_unless_zero(bo);
414413
}
415414

416415
drm_vma_offset_unlock_lookup(&bdev->vma_manager);

include/drm/ttm/ttm_bo_api.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
312312
return bo;
313313
}
314314

315+
/**
316+
* ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless
317+
* its refcount has already reached zero.
318+
* @bo: The buffer object.
319+
*
320+
* Used to reference a TTM buffer object in lookups where the object is removed
321+
* from the lookup structure during the destructor and for RCU lookups.
322+
*
323+
* Returns: @bo if the referencing was successful, NULL otherwise.
324+
*/
325+
static inline __must_check struct ttm_buffer_object *
326+
ttm_bo_get_unless_zero(struct ttm_buffer_object *bo)
327+
{
328+
if (!kref_get_unless_zero(&bo->kref))
329+
return NULL;
330+
return bo;
331+
}
332+
315333
/**
316334
* ttm_bo_wait - wait for buffer idle.
317335
*

0 commit comments

Comments
 (0)