This is to address the Coverity explicit null dereferenced warnings by NULL returns from amdgpu_mes_ctx_get_offs* but without follow-up Checks. Meanwhile refactor the code to keep only one *_get_gpu/cpu_addr. Signed-off-by: Tim Huang <tim.huang@xxxxxxx> --- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 14 ++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 17 +++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 14 +++++++------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 8 ++++---- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 14 +++++++------- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 12 ++++++------ drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 12 ++++++------ drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 12 ++++++------ drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 12 ++++++------ 11 files changed, 55 insertions(+), 64 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c index e499d6ba306b..fb708b695db8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c @@ -1082,7 +1082,7 @@ int amdgpu_mes_add_ring(struct amdgpu_device *adev, int gang_id, int offset = offsetof(struct amdgpu_mes_ctx_meta_data, compute[ring->idx].mec_hpd); ring->eop_gpu_addr = - amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); + amdgpu_ring_get_gpu_addr(ring, offset); } switch (queue_type) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c index ad49cecb20b8..01dd7b30ba74 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c @@ -169,16 +169,6 @@ void amdgpu_ring_undo(struct amdgpu_ring *ring) ring->funcs->end_use(ring); } -#define amdgpu_ring_get_gpu_addr(ring, offset) \ - (ring->is_mes_queue ? \ - (ring->mes_ctx->meta_data_gpu_addr + offset) : \ - (ring->adev->wb.gpu_addr + offset * 4)) - -#define amdgpu_ring_get_cpu_addr(ring, offset) \ - (ring->is_mes_queue ? \ - (void *)((uint8_t *)(ring->mes_ctx->meta_data_ptr) + offset) : \ - (&ring->adev->wb.wb[offset])) - /** * amdgpu_ring_init - init driver ring struct. * @@ -332,8 +322,8 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_RING_OFFS); - ring->gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - ring->ring = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + ring->gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + ring->ring = amdgpu_ring_get_cpu_addr(ring, offset); amdgpu_ring_clear_ring(ring); } else if (ring->ring_obj == NULL) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h index 582053f1cd56..f65f13d147b4 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h @@ -436,14 +436,15 @@ static inline void amdgpu_ring_patch_cond_exec(struct amdgpu_ring *ring, ring->ring[offset] = cur - offset; } -#define amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset) \ - (ring->is_mes_queue && ring->mes_ctx ? \ - (ring->mes_ctx->meta_data_gpu_addr + offset) : 0) - -#define amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset) \ - (ring->is_mes_queue && ring->mes_ctx ? \ - (void *)((uint8_t *)(ring->mes_ctx->meta_data_ptr) + offset) : \ - NULL) +#define amdgpu_ring_get_gpu_addr(ring, offset) \ + (ring->is_mes_queue ? \ + (ring->mes_ctx->meta_data_gpu_addr + offset) : \ + (ring->adev->wb.gpu_addr + offset * 4)) + +#define amdgpu_ring_get_cpu_addr(ring, offset) \ + (ring->is_mes_queue ? \ + ((void *)((uint8_t *)(ring->mes_ctx->meta_data_ptr) + offset)) : \ + ((void *)(&ring->adev->wb.wb[offset]))) int amdgpu_ring_test_helper(struct amdgpu_ring *ring); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c index 183a976ba29d..8eca0f1733ce 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c @@ -80,7 +80,7 @@ uint64_t amdgpu_sdma_get_csa_mc_addr(struct amdgpu_ring *ring, offset = offsetof(struct amdgpu_mes_ctx_meta_data, sdma[ring->idx].sdma_meta_data); - csa_mc_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); + csa_mc_addr = amdgpu_ring_get_gpu_addr(ring, offset); } else { r = amdgpu_sdma_get_index_from_ring(ring, &index); diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c index dcef39907449..abda3fba1cba 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c @@ -546,11 +546,11 @@ static int gfx_v11_0_ring_test_ib(struct amdgpu_ring *ring, long timeout) padding = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - ib.gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - ib.ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + ib.gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + ib.ptr = amdgpu_ring_get_cpu_addr(ring, offset); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, padding); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, padding); *cpu_ptr = cpu_to_le32(0xCAFEDEAD); } else { r = amdgpu_device_wb_get(adev, &index); @@ -5895,14 +5895,14 @@ static void gfx_v11_0_ring_emit_de_meta(struct amdgpu_ring *ring, bool resume) gfx[0].gfx_meta_data) + offsetof(struct v10_gfx_meta_data, de_payload); de_payload_gpu_addr = - amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); + amdgpu_ring_get_gpu_addr(ring, offset); de_payload_cpu_addr = - amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + amdgpu_ring_get_cpu_addr(ring, offset); offset = offsetof(struct amdgpu_mes_ctx_meta_data, gfx[0].gds_backup) + offsetof(struct v10_gfx_meta_data, de_payload); - gds_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); + gds_addr = amdgpu_ring_get_gpu_addr(ring, offset); } else { offset = offsetof(struct v10_gfx_meta_data, de_payload); de_payload_gpu_addr = amdgpu_csa_vaddr(ring->adev) + offset; diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c index f384be0d1800..df817b898e48 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c @@ -456,11 +456,11 @@ static int gfx_v12_0_ring_test_ib(struct amdgpu_ring *ring, long timeout) padding = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - ib.gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - ib.ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + ib.gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + ib.ptr = amdgpu_ring_get_cpu_addr(ring, offset); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, padding); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, padding); *cpu_ptr = cpu_to_le32(0xCAFEDEAD); } else { r = amdgpu_device_wb_get(adev, &index); diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c index 2929c8972ea7..b26658414f3c 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c @@ -5359,7 +5359,7 @@ static void gfx_v9_0_ring_patch_ce_meta(struct amdgpu_ring *ring, gfx[0].gfx_meta_data) + offsetof(struct v9_gfx_meta_data, ce_payload); ce_payload_cpu_addr = - amdgpu_mes_ctx_get_offs_cpu_addr(ring, payload_offset); + amdgpu_ring_get_cpu_addr(ring, payload_offset); } else { payload_offset = offsetof(struct v9_gfx_meta_data, ce_payload); ce_payload_cpu_addr = adev->virt.csa_cpu_addr + payload_offset; @@ -5391,7 +5391,7 @@ static void gfx_v9_0_ring_patch_de_meta(struct amdgpu_ring *ring, gfx[0].gfx_meta_data) + offsetof(struct v9_gfx_meta_data, de_payload); de_payload_cpu_addr = - amdgpu_mes_ctx_get_offs_cpu_addr(ring, payload_offset); + amdgpu_ring_get_cpu_addr(ring, payload_offset); } else { payload_offset = offsetof(struct v9_gfx_meta_data, de_payload); de_payload_cpu_addr = adev->virt.csa_cpu_addr + payload_offset; @@ -5590,9 +5590,9 @@ static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring, bool resume) gfx[0].gfx_meta_data) + offsetof(struct v9_gfx_meta_data, ce_payload); ce_payload_gpu_addr = - amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); + amdgpu_ring_get_gpu_addr(ring, offset); ce_payload_cpu_addr = - amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + amdgpu_ring_get_cpu_addr(ring, offset); } else { offset = offsetof(struct v9_gfx_meta_data, ce_payload); ce_payload_gpu_addr = amdgpu_csa_vaddr(ring->adev) + offset; @@ -5688,14 +5688,14 @@ static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring, bool resume, bo gfx[0].gfx_meta_data) + offsetof(struct v9_gfx_meta_data, de_payload); de_payload_gpu_addr = - amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); + amdgpu_ring_get_gpu_addr(ring, offset); de_payload_cpu_addr = - amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + amdgpu_ring_get_cpu_addr(ring, offset); offset = offsetof(struct amdgpu_mes_ctx_meta_data, gfx[0].gds_backup) + offsetof(struct v9_gfx_meta_data, de_payload); - gds_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); + gds_addr = amdgpu_ring_get_gpu_addr(ring, offset); } else { offset = offsetof(struct v9_gfx_meta_data, de_payload); de_payload_gpu_addr = amdgpu_csa_vaddr(ring->adev) + offset; diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c index b7d33d78bce0..533b1d9964b4 100644 --- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c @@ -982,8 +982,8 @@ static int sdma_v5_0_ring_test_ring(struct amdgpu_ring *ring) uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); @@ -1060,13 +1060,13 @@ static int sdma_v5_0_ring_test_ib(struct amdgpu_ring *ring, long timeout) if (ring->is_mes_queue) { uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_IB_OFFS); - ib.gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - ib.ptr = (void *)amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + ib.gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + ib.ptr = (void *)amdgpu_ring_get_cpu_addr(ring, offset); offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c index 630b03f2ce3d..e94f52e34489 100644 --- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c @@ -871,8 +871,8 @@ static int sdma_v5_2_ring_test_ring(struct amdgpu_ring *ring) uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); @@ -949,13 +949,13 @@ static int sdma_v5_2_ring_test_ib(struct amdgpu_ring *ring, long timeout) if (ring->is_mes_queue) { uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_IB_OFFS); - ib.gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - ib.ptr = (void *)amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + ib.gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + ib.ptr = amdgpu_ring_get_cpu_addr(ring, offset); offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c index dab4c2db8c9d..e29260d5b694 100644 --- a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c @@ -845,8 +845,8 @@ static int sdma_v6_0_ring_test_ring(struct amdgpu_ring *ring) uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); @@ -923,13 +923,13 @@ static int sdma_v6_0_ring_test_ib(struct amdgpu_ring *ring, long timeout) if (ring->is_mes_queue) { uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_IB_OFFS); - ib.gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - ib.ptr = (void *)amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + ib.gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + ib.ptr = amdgpu_ring_get_cpu_addr(ring, offset); offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c index 41b5e45697dc..efd3c9bdb7c6 100644 --- a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c @@ -857,8 +857,8 @@ static int sdma_v7_0_ring_test_ring(struct amdgpu_ring *ring) uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); @@ -935,13 +935,13 @@ static int sdma_v7_0_ring_test_ib(struct amdgpu_ring *ring, long timeout) if (ring->is_mes_queue) { uint32_t offset = 0; offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_IB_OFFS); - ib.gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - ib.ptr = (void *)amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + ib.gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + ib.ptr = amdgpu_ring_get_cpu_addr(ring, offset); offset = amdgpu_mes_ctx_get_offs(ring, AMDGPU_MES_CTX_PADDING_OFFS); - gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset); - cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset); + gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset); + cpu_ptr = amdgpu_ring_get_cpu_addr(ring, offset); *cpu_ptr = tmp; } else { r = amdgpu_device_wb_get(adev, &index); -- 2.43.0