pvr: fix invalid read reported by valgrind
authorFrank Binns <frank.binns@imgtec.com>
Mon, 22 May 2023 12:10:45 +0000 (13:10 +0100)
committerMarge Bot <emma+marge@anholt.net>
Thu, 25 May 2023 01:51:36 +0000 (01:51 +0000)
pvr_gpu_upload() can't be used in the case of pvr_gpu_upload_usc() as it expects
the source and destination buffers to be the same size. This isn't the case
because pvr_gpu_upload_usc() adds some padding bytes to the size passed in by
the caller.

Fixes: 547a10f8702 ("pvr: switch pvr_cmd_buffer_alloc_mem to use pvr_bo_suballoc")
Signed-off-by: Frank Binns <frank.binns@imgtec.com>
Reviewed-by: Karmjit Mahil <Karmjit.Mahil@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23185>

src/imagination/vulkan/pvr_device.c

index 2442553..35f2d0e 100644 (file)
@@ -2562,18 +2562,30 @@ VkResult pvr_gpu_upload_usc(struct pvr_device *device,
                             uint64_t code_alignment,
                             struct pvr_suballoc_bo **const pvr_bo_out)
 {
+   struct pvr_suballoc_bo *suballoc_bo = NULL;
+   VkResult result;
+   void *map;
+
    assert(code_size > 0);
 
    /* The USC will prefetch the next instruction, so over allocate by 1
     * instruction to prevent reading off the end of a page into a potentially
     * unallocated page.
     */
-   return pvr_gpu_upload(device,
-                         device->heaps.usc_heap,
-                         code,
-                         code_size + ROGUE_MAX_INSTR_BYTES,
-                         code_alignment,
-                         pvr_bo_out);
+   result = pvr_bo_suballoc(&device->suballoc_usc,
+                            code_size + ROGUE_MAX_INSTR_BYTES,
+                            code_alignment,
+                            false,
+                            &suballoc_bo);
+   if (result != VK_SUCCESS)
+      return result;
+
+   map = pvr_bo_suballoc_get_map_addr(suballoc_bo);
+   memcpy(map, code, code_size);
+
+   *pvr_bo_out = suballoc_bo;
+
+   return VK_SUCCESS;
 }
 
 /**