From 04765e6a9a43b831edd25a51a85e81f1390f36a8 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Sat, 20 Jun 2020 20:34:59 +0200 Subject: [PATCH] radv/winsys: Deal with realloc failures in BO lists. Otherwise if realloc fails we silently try to use it. Make recording fail instead. CC: Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c index 5209addacfa..fca2e53aa8a 100644 --- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c +++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c @@ -558,13 +558,20 @@ static void radv_amdgpu_cs_add_buffer_internal(struct radv_amdgpu_cs *cs, unsigned hash; int index = radv_amdgpu_cs_find_buffer(cs, bo); - if (index != -1) + if (index != -1 || cs->failed) return; if (cs->num_buffers == cs->max_num_buffers) { unsigned new_count = MAX2(1, cs->max_num_buffers * 2); - cs->handles = realloc(cs->handles, new_count * sizeof(struct drm_amdgpu_bo_list_entry)); - cs->max_num_buffers = new_count; + struct drm_amdgpu_bo_list_entry *new_entries = + realloc(cs->handles, new_count * sizeof(struct drm_amdgpu_bo_list_entry)); + if (new_entries) { + cs->max_num_buffers = new_count; + cs->handles = new_entries; + } else { + cs->failed = true; + return; + } } cs->handles[cs->num_buffers].bo_handle = bo; -- 2.30.2