From: Daniel Stone <dani...@collabora.com>

If we fail in the alloc, just use the (mostly) identical
radv_wsi_image_free() to clean up after us.

Signed-off-by: Daniel Stone <dani...@collabora.com>
---
 src/amd/vulkan/radv_wsi.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c
index bcdbd7ffe9..30999bdca6 100644
--- a/src/amd/vulkan/radv_wsi.c
+++ b/src/amd/vulkan/radv_wsi.c
@@ -207,6 +207,18 @@ fail_create_image:
        return result;
 }
 
+static void
+radv_wsi_image_free(VkDevice device,
+                   const VkAllocationCallbacks* pAllocator,
+                   struct wsi_image_base *wsi_image)
+{
+       if (wsi_image->linear_image != VK_NULL_HANDLE)
+               radv_DestroyImage(device, wsi_image->linear_image, pAllocator);
+       if (wsi_image->linear_memory != VK_NULL_HANDLE)
+               radv_FreeMemory(device, wsi_image->linear_memory, pAllocator);
+       radv_DestroyImage(device, wsi_image->image, pAllocator);
+       radv_FreeMemory(device, wsi_image->memory, pAllocator);
+}
 
 static VkResult
 radv_wsi_image_create(VkDevice device_h,
@@ -230,7 +242,7 @@ radv_wsi_image_create(VkDevice device_h,
                                              true, &wsi_image->linear_image,
                                              &wsi_image->linear_memory);
                if (result != VK_SUCCESS)
-                       goto fail_alloc;
+                       goto fail;
        } else {
                wsi_image->linear_image = VK_NULL_HANDLE;
                wsi_image->linear_memory = VK_NULL_HANDLE;
@@ -244,7 +256,7 @@ radv_wsi_image_create(VkDevice device_h,
 
        RADV_FROM_HANDLE(radv_device, device, device_h);
        if (!radv_get_memory_fd(device, memory, &wsi_image->fds[0]))
-               goto fail_linear;
+               goto fail;
 
        wsi_image->num_planes = 1;
        wsi_image->sizes[0] = image->size;
@@ -258,30 +270,11 @@ radv_wsi_image_create(VkDevice device_h,
 
        return VK_SUCCESS;
 
-fail_linear:
-       if (wsi_image->linear_memory != VK_NULL_HANDLE)
-               radv_FreeMemory(device_h, wsi_image->linear_memory, pAllocator);
-       if (wsi_image->linear_image != VK_NULL_HANDLE)
-               radv_DestroyImage(device_h, wsi_image->linear_image, 
pAllocator);
-fail_alloc:
-       radv_FreeMemory(device_h, wsi_image->memory, pAllocator);
-       radv_DestroyImage(device_h, wsi_image->image, pAllocator);
+fail:
+       radv_wsi_image_free(device_h, pAllocator, wsi_image);
        return result;
 }
 
-static void
-radv_wsi_image_free(VkDevice device,
-                   const VkAllocationCallbacks* pAllocator,
-                   struct wsi_image_base *wsi_image)
-{
-       if (wsi_image->linear_image != VK_NULL_HANDLE)
-               radv_DestroyImage(device, wsi_image->linear_image, pAllocator);
-       if (wsi_image->linear_memory != VK_NULL_HANDLE)
-               radv_FreeMemory(device, wsi_image->linear_memory, pAllocator);
-       radv_DestroyImage(device, wsi_image->image, pAllocator);
-       radv_FreeMemory(device, wsi_image->memory, pAllocator);
-}
-
 static const struct wsi_image_fns radv_wsi_image_fns = {
    .create_wsi_image = radv_wsi_image_create,
    .free_wsi_image = radv_wsi_image_free,
-- 
2.13.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to