pvr: Don't rely on GNU void pointer arithmetic
authorMatt Coster <matt.coster@imgtec.com>
Wed, 20 Sep 2023 15:34:43 +0000 (16:34 +0100)
committerMarge Bot <emma+marge@anholt.net>
Wed, 27 Sep 2023 15:25:32 +0000 (15:25 +0000)
Besides being not standard C, one instance (in pvr_cmd_buffer.c) was a
bug caused by adding-then-casting, which would likely have been caught
if void pointer arithmetic were not allowed.

All instances detected by -Wpointer-arith have been fixed here.

Signed-off-by: Matt Coster <matt.coster@imgtec.com>
Reviewed-by: Karmjit Mahil <Karmjit.Mahil@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25327>

src/imagination/common/pvr_dump.h
src/imagination/vulkan/pvr_cmd_buffer.c
src/imagination/vulkan/pvr_csb.c
src/imagination/vulkan/pvr_device.c
src/imagination/vulkan/pvr_dump_csb.c

index 3a35227..cd1f2b5 100644 (file)
@@ -300,7 +300,7 @@ bool pvr_dump_buffer_hex(struct pvr_dump_buffer_ctx *ctx, uint64_t nr_bytes);
 static inline void __pvr_dump_buffer_advance(struct pvr_dump_buffer_ctx *ctx,
                                              const uint64_t nr_bytes)
 {
-   ctx->ptr += nr_bytes;
+   ctx->ptr = (uint8_t *)ctx->ptr + nr_bytes;
    ctx->remaining_size -= nr_bytes;
 }
 
@@ -321,7 +321,7 @@ static inline bool pvr_dump_buffer_advance(struct pvr_dump_buffer_ctx *ctx,
 static inline void __pvr_dump_buffer_rewind(struct pvr_dump_buffer_ctx *ctx,
                                             const uint32_t nr_bytes)
 {
-   ctx->ptr -= nr_bytes;
+   ctx->ptr = (uint8_t *)ctx->ptr - nr_bytes;
    ctx->remaining_size += nr_bytes;
 }
 
index 5f50adc..5beaebf 100644 (file)
@@ -7071,7 +7071,7 @@ pvr_execute_deferred_cmd_buffer(struct pvr_cmd_buffer *cmd_buffer,
             prim_db_elems + cmd->dbsc2.state.depthbias_index;
 
          uint32_t *const addr =
-            pvr_bo_suballoc_get_map_addr(cmd->dbsc2.ppp_cs_bo) +
+            (uint32_t *)pvr_bo_suballoc_get_map_addr(cmd->dbsc2.ppp_cs_bo) +
             cmd->dbsc2.patch_offset;
 
          assert(pvr_bo_suballoc_get_map_addr(cmd->dbsc2.ppp_cs_bo));
index d4975e1..44571b9 100644 (file)
@@ -283,8 +283,8 @@ static bool pvr_csb_buffer_extend(struct pvr_csb *csb)
 
       csb->next = csb->relocation_mark;
 
-      csb->end += stream_link_space;
-      assert(csb->next + stream_link_space <= csb->end);
+      csb->end = (uint8_t *)csb->end + stream_link_space;
+      assert((uint8_t *)csb->next + stream_link_space <= (uint8_t *)csb->end);
 
       pvr_csb_emit_link_unmarked(csb, pvr_bo->vma->dev_addr, false);
    }
@@ -295,8 +295,8 @@ static bool pvr_csb_buffer_extend(struct pvr_csb *csb)
    /* Reserve space at the end, including the default guard padding, to make
     * sure we don't run out of space when a stream link is required.
     */
-   csb->end = csb->start + pvr_bo->bo->size - stream_reserved_space;
-   csb->next = csb->start + current_state_update_size;
+   csb->end = (uint8_t *)csb->start + pvr_bo->bo->size - stream_reserved_space;
+   csb->next = (uint8_t *)csb->start + current_state_update_size;
 
    list_addtail(&pvr_bo->link, &csb->pvr_bo_list);
 
@@ -335,7 +335,7 @@ void *pvr_csb_alloc_dwords(struct pvr_csb *csb, uint32_t num_dwords)
       mesa_logd_once("CS memory without relocation mark detected.");
 #endif
 
-   if (csb->next + required_space > csb->end) {
+   if ((uint8_t *)csb->next + required_space > (uint8_t *)csb->end) {
       bool ret = pvr_csb_buffer_extend(csb);
       if (!ret)
          return NULL;
@@ -343,7 +343,7 @@ void *pvr_csb_alloc_dwords(struct pvr_csb *csb, uint32_t num_dwords)
 
    p = csb->next;
 
-   csb->next += required_space;
+   csb->next = (uint8_t *)csb->next + required_space;
    assert(csb->next <= csb->end);
 
    return p;
index be0185e..c9d69ee 100644 (file)
@@ -2336,7 +2336,7 @@ VkResult pvr_MapMemory(VkDevice _device,
 
    /* Check if already mapped */
    if (mem->bo->map) {
-      *ppData = mem->bo->map + offset;
+      *ppData = (uint8_t *)mem->bo->map + offset;
       return VK_SUCCESS;
    }
 
@@ -2345,7 +2345,7 @@ VkResult pvr_MapMemory(VkDevice _device,
    if (result != VK_SUCCESS)
       return result;
 
-   *ppData = mem->bo->map + offset;
+   *ppData = (uint8_t *)mem->bo->map + offset;
 
    return VK_SUCCESS;
 }
index fd8fbd7..95e917d 100644 (file)
@@ -2364,7 +2364,7 @@ static bool dump_first_buffer(struct pvr_dump_buffer_ctx *const ctx,
    if (!ret)
       pvr_dump_println(&ctx->base,
                        "<error while decoding at 0x%tx>",
-                       ctx->ptr - ctx->initial_ptr);
+                       (uint8_t *)ctx->ptr - (uint8_t *)ctx->initial_ptr);
 
    pvr_dump_buffer_restart(ctx);
    pvr_dump_mark_section(&ctx->base, "First buffer hexdump");