]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe: fix refcount leak in xe_range_fence_insert()
authorWentao Liang <vulab@iscas.ac.cn>
Wed, 10 Jun 2026 17:27:05 +0000 (10:27 -0700)
committerMatthew Brost <matthew.brost@intel.com>
Thu, 11 Jun 2026 13:39:40 +0000 (06:39 -0700)
xe_range_fence_insert() acquires a reference on fence via
dma_fence_get() and stores it in rfence->fence.  It then calls
dma_fence_add_callback() and handles two cases: when the callback
is successfully registered (err == 0) the fence is transferred to
the tree for later cleanup; when the fence is already signaled
(err == -ENOENT) it manually drops the extra reference with
dma_fence_put(fence).

However, dma_fence_add_callback() can fail with other errors
(e.g. -EINVAL) and in that case the code falls through to the free:
label without releasing the acquired reference, leaking it.

Fix the leak by adding an else branch that calls dma_fence_put()
before jumping to free: for any error other than -ENOENT.

Fixes: 845f64bdbfc9 ("drm/xe: Introduce a range-fence utility")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patch.msgid.link/20260610172705.3450560-1-matthew.brost@intel.com
(cherry picked from commit 98c4a4201290823c2c5c7ba21692bd9a64b61021)
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
drivers/gpu/drm/xe/xe_range_fence.c

index 372378e89e989239833879e23d2e62a2fd573b54..3d8fa194a7b0eb66c6c9b3cbbb56931f393cfd73 100644 (file)
@@ -77,6 +77,8 @@ int xe_range_fence_insert(struct xe_range_fence_tree *tree,
        } else if (err == 0) {
                xe_range_fence_tree_insert(rfence, &tree->root);
                return 0;
+       } else {
+               dma_fence_put(fence);
        }
 
 free: