Module: Mesa Branch: main Commit: d4878636fe77f3866ee7ca1f2364f83c91c9cd1c URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d4878636fe77f3866ee7ca1f2364f83c91c9cd1c
Author: Yiwei Zhang <[email protected]> Date: Fri Aug 20 21:06:25 2021 +0000 venus: refactor failure path for sets allocation Signed-off-by: Yiwei Zhang <[email protected]> Reviewed-by: Chia-I Wu <[email protected]> Reviewed-by: Ryan Neph <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12501> --- src/virtio/vulkan/vn_descriptor_set.c | 48 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/virtio/vulkan/vn_descriptor_set.c b/src/virtio/vulkan/vn_descriptor_set.c index d5d0f484c4d..93ac44fc01f 100644 --- a/src/virtio/vulkan/vn_descriptor_set.c +++ b/src/virtio/vulkan/vn_descriptor_set.c @@ -243,21 +243,16 @@ vn_AllocateDescriptorSets(VkDevice device, struct vn_descriptor_pool *pool = vn_descriptor_pool_from_handle(pAllocateInfo->descriptorPool); const VkAllocationCallbacks *alloc = &pool->allocator; + VkResult result; for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { struct vn_descriptor_set *set = vk_zalloc(alloc, sizeof(*set), VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!set) { - for (uint32_t j = 0; j < i; j++) { - set = vn_descriptor_set_from_handle(pDescriptorSets[j]); - list_del(&set->head); - vn_object_base_fini(&set->base); - vk_free(alloc, set); - } - memset(pDescriptorSets, 0, - sizeof(*pDescriptorSets) * pAllocateInfo->descriptorSetCount); - return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY); + pDescriptorSets[i] = VK_NULL_HANDLE; + result = VK_ERROR_OUT_OF_HOST_MEMORY; + goto fail; } vn_object_base_init(&set->base, VK_OBJECT_TYPE_DESCRIPTOR_SET, @@ -270,22 +265,29 @@ vn_AllocateDescriptorSets(VkDevice device, pDescriptorSets[i] = set_handle; } - VkResult result = vn_call_vkAllocateDescriptorSets( - dev->instance, device, pAllocateInfo, pDescriptorSets); - if (result != VK_SUCCESS) { - for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { - struct vn_descriptor_set *set = - vn_descriptor_set_from_handle(pDescriptorSets[i]); - list_del(&set->head); - vn_object_base_fini(&set->base); - vk_free(alloc, set); - } - memset(pDescriptorSets, 0, - sizeof(*pDescriptorSets) * pAllocateInfo->descriptorSetCount); - return vn_error(dev->instance, result); - } + result = vn_call_vkAllocateDescriptorSets(dev->instance, device, + pAllocateInfo, pDescriptorSets); + if (result != VK_SUCCESS) + goto fail; return VK_SUCCESS; + +fail: + for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { + struct vn_descriptor_set *set = + vn_descriptor_set_from_handle(pDescriptorSets[i]); + if (!set) + break; + + list_del(&set->head); + vn_object_base_fini(&set->base); + vk_free(alloc, set); + } + + memset(pDescriptorSets, 0, + sizeof(*pDescriptorSets) * pAllocateInfo->descriptorSetCount); + + return vn_error(dev->instance, result); } VkResult
