]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdkfd: fix a memory leak in device_queue_manager_init()
authorHaoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Thu, 8 Jan 2026 07:18:22 +0000 (15:18 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Sat, 10 Jan 2026 19:21:52 +0000 (14:21 -0500)
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: 11614c36bc8f ("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>
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

index 9bc80f8ba7dcd8263367676b1127ea933975dc34..dc4b6d19dc10cc905dff99728571a51f49c1ebc8 100644 (file)
@@ -2916,6 +2916,14 @@ static int allocate_hiq_sdma_mqd(struct device_queue_manager *dqm)
        return retval;
 }
 
+static void deallocate_hiq_sdma_mqd(struct kfd_node *dev,
+                                   struct kfd_mem_obj *mqd)
+{
+       WARN(!mqd, "No hiq sdma mqd trunk to free");
+
+       amdgpu_amdkfd_free_gtt_mem(dev->adev, &mqd->gtt_mem);
+}
+
 struct device_queue_manager *device_queue_manager_init(struct kfd_node *dev)
 {
        struct device_queue_manager *dqm;
@@ -3041,19 +3049,14 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_node *dev)
                return dqm;
        }
 
+       if (!dev->kfd->shared_resources.enable_mes)
+               deallocate_hiq_sdma_mqd(dev, &dqm->hiq_sdma_mqd);
+
 out_free:
        kfree(dqm);
        return NULL;
 }
 
-static void deallocate_hiq_sdma_mqd(struct kfd_node *dev,
-                                   struct kfd_mem_obj *mqd)
-{
-       WARN(!mqd, "No hiq sdma mqd trunk to free");
-
-       amdgpu_amdkfd_free_gtt_mem(dev->adev, &mqd->gtt_mem);
-}
-
 void device_queue_manager_uninit(struct device_queue_manager *dqm)
 {
        dqm->ops.stop(dqm);