[PATCH] drm/amdgpu: remove dead empty checks in ring_mux ib_mark_offset and end_ib

Maoyi Xie posted 1 patch 3 days, 5 hours ago
drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c | 8 --------
1 file changed, 8 deletions(-)
[PATCH] drm/amdgpu: remove dead empty checks in ring_mux ib_mark_offset and end_ib
Posted by Maoyi Xie 3 days, 5 hours ago
amdgpu_ring_mux_ib_mark_offset() and amdgpu_ring_mux_end_ib() read
e->list with list_last_entry() and then test the returned pointer
against NULL. list_last_entry() never returns NULL. On an empty
list it returns container_of(&e->list, struct amdgpu_mux_chunk,
entry), which is an aliased pointer derived from the list head.
The "cannot find chunk!" error path is dead code.

These callsites run on the software ring submission path, after
amdgpu_ring_mux_start_ib() has linked a fresh chunk into e->list.
By the IB API contract, mark_offset and end_ib only execute between
start_ib and the chunk's removal in scan_and_remove_signaled_chunk(),
so e->list is non-empty at the read. The defensive check is
misleading and never fires.

Drop the dead block on both sites. The list_last_entry() read stays.
If a future change broke the precondition, callers would crash on
the aliased pointer, which is louder than the current silent error
log and easier to debug.

Suggested-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c
index 6e64a96fa285..83d62d9f76d4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c
@@ -495,10 +495,6 @@ void amdgpu_ring_mux_ib_mark_offset(struct amdgpu_ring_mux *mux,
 	}
 
 	chunk = list_last_entry(&e->list, struct amdgpu_mux_chunk, entry);
-	if (!chunk) {
-		DRM_ERROR("cannot find chunk!\n");
-		return;
-	}
 
 	switch (type) {
 	case AMDGPU_MUX_OFFSET_TYPE_CONTROL:
@@ -528,10 +524,6 @@ void amdgpu_ring_mux_end_ib(struct amdgpu_ring_mux *mux, struct amdgpu_ring *rin
 	}
 
 	chunk = list_last_entry(&e->list, struct amdgpu_mux_chunk, entry);
-	if (!chunk) {
-		DRM_ERROR("cannot find chunk!\n");
-		return;
-	}
 
 	chunk->end = ring->wptr;
 	chunk->sync_seq = READ_ONCE(ring->fence_drv.sync_seq);
-- 
2.34.1