From a87d5d2f02849231ac1636374d1b466e466db147 Mon Sep 17 00:00:00 2001

From: Zechun Dong <[email protected]>
Date: Thu, 28 May 2026 17:50:23 +0800
Subject: [PATCH] drm/amdkfd: fix memleak in kfd_procfs_add_sysfs_stats


When kfd_lookup_process_by_mm fails for a non-primary context,
the process->kobj allocated earlier in the function is not freed.
Add the missing cleanup.


Signed-off-by: Zechun Dong <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)


diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d28ca581cad0..4a47d3535cae 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -847,8 +847,11 @@ int kfd_create_process_sysfs(struct kfd_process *process)
                                           (int)process->lead_thread->pid);
        else {
                primary_process = 
kfd_lookup_process_by_mm(process->lead_thread->mm);
- if (!primary_process)
+ if (!primary_process) {
+ kobject_put(process->kobj);
+ process->kobj = NULL;
                        return -ESRCH;
+ }


                ret = kobject_init_and_add(process->kobj, &procfs_type,
                                           primary_process->kobj, "context_%u",
-- 
2.43.0
|
|


|
|


|

Reply via email to