Skip to content

Commit 80614c5

Browse files
Haoxiang Lialexdeucher
authored andcommitted
drm/amdkfd: fix a memory leak in device_queue_manager_init()
If dqm->ops.initialize() fails, add deallocate_hiq_sdma_mqd() to release the memory allocated by allocate_hiq_sdma_mqd(). Move deallocate_hiq_sdma_mqd() up to ensure proper function visibility at the point of use. Fixes: 11614c3 ("drm/amdkfd: Allocate MQD trunk for HIQ and SDMA") Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn> Signed-off-by: Felix Kuehling <felix.kuehling@amd.com> Reviewed-by: Oak Zeng <Oak.Zeng@amd.com> Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit b7cccc8) Cc: stable@vger.kernel.org
1 parent b6dff00 commit 80614c5

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,14 @@ static int allocate_hiq_sdma_mqd(struct device_queue_manager *dqm)
29192919
return retval;
29202920
}
29212921

2922+
static void deallocate_hiq_sdma_mqd(struct kfd_node *dev,
2923+
struct kfd_mem_obj *mqd)
2924+
{
2925+
WARN(!mqd, "No hiq sdma mqd trunk to free");
2926+
2927+
amdgpu_amdkfd_free_gtt_mem(dev->adev, &mqd->gtt_mem);
2928+
}
2929+
29222930
struct device_queue_manager *device_queue_manager_init(struct kfd_node *dev)
29232931
{
29242932
struct device_queue_manager *dqm;
@@ -3042,19 +3050,14 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_node *dev)
30423050
return dqm;
30433051
}
30443052

3053+
if (!dev->kfd->shared_resources.enable_mes)
3054+
deallocate_hiq_sdma_mqd(dev, &dqm->hiq_sdma_mqd);
3055+
30453056
out_free:
30463057
kfree(dqm);
30473058
return NULL;
30483059
}
30493060

3050-
static void deallocate_hiq_sdma_mqd(struct kfd_node *dev,
3051-
struct kfd_mem_obj *mqd)
3052-
{
3053-
WARN(!mqd, "No hiq sdma mqd trunk to free");
3054-
3055-
amdgpu_amdkfd_free_gtt_mem(dev->adev, &mqd->gtt_mem);
3056-
}
3057-
30583061
void device_queue_manager_uninit(struct device_queue_manager *dqm)
30593062
{
30603063
dqm->ops.stop(dqm);

0 commit comments

Comments
 (0)