Skip to contentSkip to conversation

drm/amdkfd: Fix Null Pointer Derefernce

PATCH In review Sunday Clement 2 participants 2 messages Feb 6

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: Fix Null Pointer Derefernce

It doesn't really makes sense to dereference the kfd_process pointer then check if its null right after, the order of the instructions has been changed to address this and properly check for a null pointer.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -3
index 732ad1224a61..1db565442c48 100644
@@ -3170,11 +3170,11 @@ static int kfd_ioctl_create_process(struct file *filep, struct kfd_process *p, v
 	struct kfd_process *process;
 	int ret;
 
-	/* Each FD owns only one kfd_process */
-	if (p->context_id != KFD_CONTEXT_ID_PRIMARY)
+	if (!filep->private_data || !p)
 		return -EINVAL;
 
-	if (!filep->private_data || !p)
+	/* Each FD owns only one kfd_process */
+	if (p->context_id != KFD_CONTEXT_ID_PRIMARY)
 		return -EINVAL;
 
 	mutex_lock(&kfd_processes_mutex);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

[Public]

________________________________
From: Clement, Sunday <[email protected]>
Sent: Friday, February 6, 2026 10:53 AM
To: [email protected] <[email protected]>
Cc: Kasiviswanathan, Harish <[email protected]>; Russell, Kent <[email protected]>; Kuehling, Felix <[email protected]>; Clement, Sunday <[email protected]>
Subject: [PATCH] drm/amdkfd: Fix Null Pointer Derefernce

It doesn't really makes sense to dereference the kfd_process pointer then check if its null right after, the order of the instructions has been changed to address this and properly check for a null pointer.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -3
index 732ad1224a61..1db565442c48 100644
@@ -3170,11 +3170,11 @@ static int kfd_ioctl_create_process(struct file *filep, struct kfd_process *p, v
         struct kfd_process *process;
         int ret;
 
-       /* Each FD owns only one kfd_process */
-       if (p->context_id != KFD_CONTEXT_ID_PRIMARY)
+       if (!filep->private_data || !p)
                 return -EINVAL;
 
-       if (!filep->private_data || !p)
+       /* Each FD owns only one kfd_process */
+       if (p->context_id != KFD_CONTEXT_ID_PRIMARY)
                 return -EINVAL;
 
         mutex_lock(&kfd_processes_mutex);

--
2.43.0