From 20b42f446667d01d7861b52f667bcd6b1569b9c2 Mon Sep 17 00:00:00 2001 From: Luigi Santivetti Date: Mon, 27 Apr 2026 14:28:42 +0100 Subject: [PATCH] pvr: de-dup strncmp in pvrsrvkm winsys Signed-off-by: Luigi Santivetti Reviewed-by: Frank Binns Part-of: --- .../vulkan/winsys/pvrsrvkm/pvr_srv.c | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c b/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c index d65321e2be6..341f07e05e8 100644 --- a/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c +++ b/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c @@ -251,39 +251,40 @@ static VkResult pvr_srv_memctx_init(struct pvr_srv_winsys *srv_ws) if (result != VK_SUCCESS) goto err_pvr_srv_int_ctx_destroy; - if (general_heap_idx == -1 && - strncmp(heap_name, - PVR_SRV_GENERAL_HEAP_IDENT, - sizeof(PVR_SRV_GENERAL_HEAP_IDENT)) == 0) { +#define pvr_srv_heap_needs_init(heap_index, name1, name2) \ + ((heap_index) == -1 && \ + strncmp((name1), \ + (name2), \ + sizeof((name2))) == 0) + + if (pvr_srv_heap_needs_init(general_heap_idx, heap_name, + PVR_SRV_GENERAL_HEAP_IDENT)) { general_heap_idx = i; - } else if (pds_heap_idx == -1 && - strncmp(heap_name, - PVR_SRV_PDSCODEDATA_HEAP_IDENT, - sizeof(PVR_SRV_PDSCODEDATA_HEAP_IDENT)) == 0) { + + } else if (pvr_srv_heap_needs_init(pds_heap_idx, heap_name, + PVR_SRV_PDSCODEDATA_HEAP_IDENT)) { pds_heap_idx = i; - } else if (rgn_hdr_heap_idx == -1 && - strncmp(heap_name, - PVR_SRV_RGNHDR_BRN_63142_HEAP_IDENT, - sizeof(PVR_SRV_RGNHDR_BRN_63142_HEAP_IDENT)) == 0) { + + } else if (pvr_srv_heap_needs_init(rgn_hdr_heap_idx, heap_name, + PVR_SRV_RGNHDR_BRN_63142_HEAP_IDENT)) { rgn_hdr_heap_idx = i; - } else if (transfer_3d_heap_idx == -1 && - strncmp(heap_name, - PVR_SRV_TRANSFER_3D_HEAP_IDENT, - sizeof(PVR_SRV_TRANSFER_3D_HEAP_IDENT)) == 0) { + + } else if (pvr_srv_heap_needs_init(transfer_3d_heap_idx, heap_name, + PVR_SRV_TRANSFER_3D_HEAP_IDENT)) { transfer_3d_heap_idx = i; - } else if (usc_heap_idx == -1 && - strncmp(heap_name, - PVR_SRV_USCCODE_HEAP_IDENT, - sizeof(PVR_SRV_USCCODE_HEAP_IDENT)) == 0) { + + } else if (pvr_srv_heap_needs_init(usc_heap_idx, heap_name, + PVR_SRV_USCCODE_HEAP_IDENT)) { usc_heap_idx = i; - } else if (vis_test_heap_idx == -1 && - strncmp(heap_name, - PVR_SRV_VISIBILITY_TEST_HEAP_IDENT, - sizeof(PVR_SRV_VISIBILITY_TEST_HEAP_IDENT)) == 0) { + + } else if (pvr_srv_heap_needs_init(vis_test_heap_idx, heap_name, + PVR_SRV_VISIBILITY_TEST_HEAP_IDENT)) { vis_test_heap_idx = i; } } +#undef pvr_srv_heap_needs_init + /* Check for and initialise required heaps. */ if (general_heap_idx == -1 || pds_heap_idx == -1 || transfer_3d_heap_idx == -1 || usc_heap_idx == -1 ||