tu/drm/virtio: Fix GEM handle leak on failed dmabuf res_id lookup

When vdrm_handle_to_res_id fails in virtio_bo_init_dmabuf, the handle
obtained from vdrm_dmabuf_to_handle was leaked.
Closing the handle is safe despite the lack of vdrm refcounting
because dma_bo_lock is held and already-imported BOs return early.
At this point, we are the sole holder of the handle.

While here, use the local vdrm variable consistently.

Fixes: 6ca192f586 ("turnip: virtio: fix iova leak upon found already imported dmabuf")
Signed-off-by: Valentine Burley <valentine.burley@collabora.com>
(cherry picked from commit f2c89f0188)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40752>
This commit is contained in:
Valentine Burley 2026-03-20 11:33:46 +01:00 committed by Eric Engestrom
parent e984faec26
commit bb0c3b12b9
2 changed files with 3 additions and 3 deletions

View file

@ -3824,7 +3824,7 @@
"description": "tu/drm/virtio: Fix GEM handle leak on failed dmabuf res_id lookup",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "6ca192f586fe1470a97b6f34bce7761a760ce15d",
"notes": null

View file

@ -822,7 +822,7 @@ virtio_bo_init_dmabuf(struct tu_device *dev,
res_id = vdrm_handle_to_res_id(vdrm, handle);
if (!res_id) {
/* XXX gem_handle potentially leaked here since no refcnt */
vdrm_bo_close(vdrm, handle);
result = vk_error(dev, VK_ERROR_INVALID_EXTERNAL_HANDLE);
goto out_unlock;
}
@ -844,7 +844,7 @@ virtio_bo_init_dmabuf(struct tu_device *dev,
TU_BO_ALLOC_DMABUF, &iova);
mtx_unlock(&dev->vma_mutex);
if (result != VK_SUCCESS) {
vdrm_bo_close(dev->vdev->vdrm, handle);
vdrm_bo_close(vdrm, handle);
goto out_unlock;
}