[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Haoxiang Li <[email protected]>
Sent: Monday, January 5, 2026 8:58 PM
To: Kuehling, Felix <[email protected]>; Deucher, Alexander 
<[email protected]>; Koenig, Christian <[email protected]>; 
[email protected]; [email protected]; Zeng, Oak <[email protected]>
Cc: [email protected]; [email protected]; 
[email protected]; Haoxiang Li <[email protected]>; 
[email protected]
Subject: [PATCH v2] drm/amdkfd: fix a memory leak in device_queue_manager_init()

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


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")
Cc: [email protected]
Signed-off-by: Haoxiang Li <[email protected]>
---
Changes in v2:
- Move deallocate_hiq_sdma_mqd() up. Thanks, Felix!
- Add a Fixes tag.
---
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index d7a2e7178ea9..8af0929ca40a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -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); }

} in last line should be in a new line.

Other than that, patch lgtm. Reviewed-by: [email protected]
+
 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);
--
2.25.1

Reply via email to