lavapipe: do not close import fd on error and amend an error code

The implementation only takes the ownership after a successful import.
On import failure, the caller is going to handle the fd. Meanwhile,
amend a missing error code on an error path.

Fixes: 895d3399f7 ("lavapipe: add support for KHR_external_memory_fd")
Reviewed-by: Lucas Fryzek <lfryzek@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36204>
(cherry picked from commit 160cd3a317)
This commit is contained in:
Yiwei Zhang 2025-07-17 20:08:46 -07:00 committed by Eric Engestrom
parent 2f74be6233
commit 55071f8bb1
2 changed files with 2 additions and 3 deletions

View file

@ -5524,7 +5524,7 @@
"description": "lavapipe: do not close import fd on error and amend an error code",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "895d3399f7fb5cf58aa857fb2b98f23fe89071ba",
"notes": null

View file

@ -2002,13 +2002,12 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory(
bool dmabuf = import_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
uint64_t size;
if(!device->pscreen->import_memory_fd(device->pscreen, import_info->fd, &mem->pmem, &size, dmabuf)) {
close(import_info->fd);
error = VK_ERROR_INVALID_EXTERNAL_HANDLE;
goto fail;
}
if(size < pAllocateInfo->allocationSize) {
device->pscreen->free_memory_fd(device->pscreen, mem->pmem);
close(import_info->fd);
error = VK_ERROR_INVALID_EXTERNAL_HANDLE;
goto fail;
}
if (export_info && export_info->handleTypes == import_info->handleType) {