drm/amdkfd: FORWARD NULL
Subsystems (3)
PATCH v4 1/1 drm/amdkfd: FORWARD NULL
This patch fixes issues when the code moves forward with a potential NULL pointer, without checking.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 12 ++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 --- 4 files changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +1 -1
@@ -107,7 +107,7 @@ static const char *amdkfd_fence_get_timeline_name(struct dma_fence *f) {struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); -return fence->timeline_name; +return fence ? fence->timeline_name :NULL ; }/**
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
@@ -2358,7 +2358,7 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image,if (kdev->kfd->hive_id) {for (nid =0 ; nid < proximity_domain; ++nid) { peer_dev =kfd_topology_device_by_proximity_domain_no_lock (nid); -if (!peer_dev->gpu) +if (!peer_dev || !peer_dev->gpu)continue ;if (peer_dev->gpu->kfd->hive_id != kdev->kfd->hive_id)continue ;
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +10 -2
@@ -516,9 +516,13 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)int i, r =0 , rewind_count =0 ;for (i =0 ; i < target->n_pdds; i++) { +uint32_t caps;struct kfd_topology_device *topo_dev = -kfd_topology_device_by_id (target->pdds[i]->dev->id); -uint32_t caps = topo_dev->node_props.capability; +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +return -EINVAL ; + + caps = topo_dev->node_props.capability;if (!(caps &HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED ) && (*flags &KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP )) {
@@ -1071,6 +1075,10 @@ int kfd_dbg_trap_device_snapshot(struct kfd_process *target,for (i =0 ; i < tmp_num_devices; i++) {struct kfd_process_device *pdd = target->pdds[i];struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (pdd->dev->id); +if (!topo_dev) { + r = -EINVAL ; +break ; + } device_info.gpu_id = pdd->dev->id; device_info.exception_status = pdd->exception_status;
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -3
@@ -1763,9 +1763,6 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,struct kfd_node *dev;int ret; -if (!drm_file) -return -EINVAL ; -if (pdd->drm_priv)return -EBUSY ;
Signature · 1 line
2.43.0
Please change the commit headline. Suggestion: "Check for NULL return values"
One more comment inline ...
Quoted 73 lines · Andrew Martin
This patch fixes issues when the code moves forward with a potential NULL pointer, without checking.
Signed-off-by Andrew Martin <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 12 ++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 --- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +1
-1@@ -107,7 +107,7 @@ static const char *amdkfd_fence_get_timeline_name(struct dma_fence *f) {struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); -return fence->timeline_name; +return fence ? fence->timeline_name :NULL ; }/** drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-1@@ -2358,7 +2358,7 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image,if (kdev->kfd->hive_id) {for (nid =0 ; nid < proximity_domain; ++nid) { peer_dev =kfd_topology_device_by_proximity_domain_no_lock (nid); -if (!peer_dev->gpu) +if (!peer_dev || !peer_dev->gpu)continue ;if (peer_dev->gpu->kfd->hive_id != kdev->kfd->hive_id)continue ;drivers/gpu/drm/amd/amdkfd/kfd_debug.c +10
-2@@ -516,9 +516,13 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)int i, r =0 , rewind_count =0 ;for (i =0 ; i < target->n_pdds; i++) { +uint32_t caps;struct kfd_topology_device *topo_dev = -kfd_topology_device_by_id (target->pdds[i]->dev->id); -uint32_t caps = topo_dev->node_props.capability; +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +return -EINVAL ; + + caps = topo_dev->node_props.capability;if (!(caps &HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED ) && (*flags &KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP )) {@@ -1071,6 +1075,10 @@ int kfd_dbg_trap_device_snapshot(struct kfd_process *target,for (i =0 ; i < tmp_num_devices; i++) {struct kfd_process_device *pdd = target->pdds[i];struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (pdd->dev->id); +if (!topo_dev) { + r = -EINVAL ; +break ; + } device_info.gpu_id = pdd->dev->id; device_info.exception_status = pdd->exception_status;drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1768
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-3@@ -1763,9 +1763,6 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,struct kfd_node *dev;int ret; -if (!drm_file) -return -EINVAL ; -
This is kind of the opposite of the rest of this patch. If you want to keep this in here, please call it out in the commit description with something like
"Removed one redundant NULL check for a function parameter. This check is already done in the only caller."
With that fixed, the patch is
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0if (pdd->drm_priv)return -EBUSY ;
[AMD Official Use Only - AMD Internal Distribution Only]
Greetings @Kuehling, Felix
Thanks for the RB. It all makes sense. BTW I kept the "opposite" change in (with the update commit message), as it was suggested by you earlier when we chatted about private/public API. I really do love all the subtle details that goes into each patches.
One love!
Quoted 118 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Friday, December 5, 2025 11:34 AM
To: [email protected]; Martin, Andrew <[email protected]>
Subject: Re: [PATCH v4] drm/amdkfd: FORWARD NULLPlease change the commit headline. Suggestion: "Check for NULL return values"
One more comment inline ...
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c static const char
Quoted 17 lines · Andrew Martin
This patch fixes issues when the code moves forward with a potential NULL pointer, without checking.
Signed-off-by Andrew Martin <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 12 ++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 --- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0@@ -107,7 +107,7 @@ static const char*amdkfd_fence_get_timeline_name(struct
dma_fence*f)drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_create_vcrat_image_gpu(void
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +1
-1{struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); -return fence->timeline_name; +return fence ? fence->timeline_name :NULL ; }/** drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0
-0@@ -2358,7 +2358,7 @@ static int kfd_create_vcrat_image_gpu(void
*pcrat_image,drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_create_vcrat_image_gpu(void *pcrat_image,
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0
-0if (kdev->kfd->hive_id) {for (nid =0 ; nid < proximity_domain; ++nid) { peer_dev =
kfd_topology_device_by_proximity_domain_no_lock(nid);drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_set_flags(struct kfd_process *target,
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-1-if (!peer_dev->gpu) +if (!peer_dev || !peer_dev->gpu)continue ;if (peer_dev->gpu->kfd->hive_id != kdev->kfd->hive_id)continue ;drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -516,9 +516,13 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target,
uint32_t*flags)Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-0int i, r =0 , rewind_count =0 ;for (i =0 ; i < target->n_pdds; i++) { +uint32_t caps; struct kfd_topology_device *topo_dev =drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +5
-2-kfd_topology_device_by_id (target->pdds[i]- dev->id); -uint32_t caps = topo_dev->node_props.capability; +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +return -EINVAL ; + + caps = topo_dev->node_props.capability; if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&Quoted 1 line
(*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) {@@ -1071,6 +1075,10
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct
Quoted 18 lines
@@ int kfd_dbg_trap_device_snapshot(struct
kfd_process*target,for (i = 0; i < tmp_num_devices; i++) { struct kfd_process_device *pdd = target->pdds[i]; struct kfd_topology_device *topo_dev =
kfd_topology_device_by_id(pdd->dev->id);drivers/gpu/drm/amd/amdkfd/kfd_debug.c +4
-0+if (!topo_dev) { + r = -EINVAL ; +break ; + } device_info.gpu_id = pdd->dev->id; device_info.exception_status = pdd->exception_status; diff --git
a/drivers/gpu/drm/amd/amdkfd/kfd_process.cb/drivers/gpu/drm/amd/amdkfd/kfd_process.c
indexaec7522407db..47783803f56f100644drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0@@ -1763,9 +1763,6 @@ int kfd_process_device_init_vm(struct
kfd_process_device*pdd,drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1768
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-3struct kfd_node *dev;int ret; -if (!drm_file) -return -EINVAL ; -This is kind of the opposite of the rest of this patch. If you want to keep this in here, please call it out in the commit description with something like
"Removed one redundant NULL check for a function parameter. This check is
already done in the only caller."With that fixed, the patch is
Reviewed-by Felix Kuehling <[email protected]>Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0if (pdd->drm_priv)return -EBUSY ;