Commit
b5629f4a0869f4b01cfbfdf27f2c349d68c5d9d4
drm/amdgpu: fix sched entity leak in ttm buffer entity init
amdgpu_ttm_buffer_entity_init() checks num_gart_windows after
drm_sched_entity_init() has already attached the entity to a
scheduler run-queue. Returning -EINVAL from that check leaks the
entity.
Move the ARRAY_SIZE() check before any resources are acquired.
Fixes: 2c3725572561 ("drm/amdgpu: statically assign gart windows to ttm entities")
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 4000d1cdd1eacd3422267d6c8b4f1c9333b0317e)
Cc: stable@vger.kernel.org
Perry Yuan <perry.yuan@amd.com> · 2026-09-10 08:57 UTC · committed by Alex Deucher
1 file changed,
+3
−2
modified drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
| @@ -2065,14 +2065,15 @@ static int amdgpu_ttm_buffer_entity_init(struct amdgpu_gtt_mgr *mgr, | |||
| 2065 | 2065 | int i, r, num_pages; | |
| 2066 | 2066 | const u64 GTT_MAX_PAGES = (AMDGPU_GTT_MAX_TRANSFER_SIZE >> PAGE_SHIFT); | |
| 2067 | 2067 | ||
| 2068 | + | if (ARRAY_SIZE(entity->gart_window_offs) < num_gart_windows) | |
| 2069 | + | return -EINVAL; | |
| 2070 | + | ||
| 2068 | 2071 | r = drm_sched_entity_init(&entity->base, prio, scheds, num_schedulers, NULL); | |
| 2069 | 2072 | if (r) | |
| 2070 | 2073 | return r; | |
| 2071 | 2074 | ||
| 2072 | 2075 | mutex_init(&entity->lock); | |
| 2073 | 2076 | ||
| 2074 | - | if (ARRAY_SIZE(entity->gart_window_offs) < num_gart_windows) | |
| 2075 | - | return -EINVAL; | |
| 2076 | 2077 | if (num_gart_windows == 0) | |
| 2077 | 2078 | return 0; | |
| 2078 | 2079 | ||