]> git.ipfire.org Git - thirdparty/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>
Wed, 14 Jan 2026 19:58:24 +0000 (14:58 -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>
(cherry picked from commit b7cccc8286bb9919a0952c812872da1dcfe9d390)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

index d7a2e7178ea9c847c928d57ec7d5fa5e8ffc355b..8af0929ca40a33b3f3f9ece799bd91963c524ae2 100644 (file)
@@ -2919,6 +2919,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;
@@ -3042,19 +3050,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);