Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+19 -2
+1 -2
drivers/gpu/drm/ttm/ttm_bo_vm.c
··· 409 409 node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages); 410 410 if (likely(node)) { 411 411 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); 414 413 } 415 414 416 415 drm_vma_offset_unlock_lookup(&bdev->vma_manager);
+18
include/drm/ttm/ttm_bo_api.h
··· 313 313 } 314 314 315 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 + 333 + /** 316 334 * ttm_bo_wait - wait for buffer idle. 317 335 * 318 336 * @bo: The buffer object.