Mesa (main): turnip: Fix allocation failure handling around device->name.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 6 17:09:50 UTC 2021


Module: Mesa
Branch: main
Commit: 36d761f2a596e2033be89d74f49c4a1df17cbc79
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=36d761f2a596e2033be89d74f49c4a1df17cbc79

Author: Emma Anholt <emma at anholt.net>
Date:   Tue Oct  5 10:22:45 2021 -0700

turnip: Fix allocation failure handling around device->name.

Fixes regressions in dEQP-VK.api.device_init.create_instance_device_intentional_alloc_fail

Fixes: 5116388e0ba9 ("turnip: Expose a device name similar to the blob.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13200>

---

 src/freedreno/vulkan/tu_device.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c
index 181772fcc48..54f66c00d48 100644
--- a/src/freedreno/vulkan/tu_device.c
+++ b/src/freedreno/vulkan/tu_device.c
@@ -212,12 +212,16 @@ tu_physical_device_init(struct tu_physical_device *device,
                                VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 
    }
+   if (!device->name) {
+      return vk_startup_errorf(instance, VK_ERROR_OUT_OF_HOST_MEMORY,
+                               "device name alloc fail");
+   }
 
    const struct fd_dev_info *info = fd_dev_info(&device->dev_id);
    if (!info) {
       result = vk_startup_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
                                  "device %s is unsupported", device->name);
-      return result;
+      goto fail;
    }
    switch (fd_dev_gen(&device->dev_id)) {
    case 6:
@@ -229,12 +233,12 @@ tu_physical_device_init(struct tu_physical_device *device,
    default:
       result = vk_startup_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
                                  "device %s is unsupported", device->name);
-      return result;
+      goto fail;
    }
    if (tu_device_get_cache_uuid(fd_dev_gpu_id(&device->dev_id), device->cache_uuid)) {
       result = vk_startup_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
                                  "cannot generate UUID");
-      return result;
+      goto fail;
    }
 
    /* The gpu id is already embedded in the uuid so we just pass "tu"
@@ -260,18 +264,22 @@ tu_physical_device_init(struct tu_physical_device *device,
                                     &supported_extensions,
                                     &dispatch_table);
    if (result != VK_SUCCESS)
-      return result;
+      goto fail;
 
 #if TU_HAS_SURFACE
    result = tu_wsi_init(device);
    if (result != VK_SUCCESS) {
       vk_startup_errorf(instance, result, "WSI init failure");
       vk_physical_device_finish(&device->vk);
-      return result;
+      goto fail;
    }
 #endif
 
    return VK_SUCCESS;
+
+fail:
+   vk_free(&instance->vk.alloc, (void *)device->name);
+   return result;
 }
 
 static void



More information about the mesa-commit mailing list