drm/amdkfd: FORWARD NULL
Subsystems (3)
PATCH 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_debug.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +2 -0
@@ -104,6 +104,8 @@ static const char *amdkfd_fence_get_driver_name(struct dma_fence *f)static const char *amdkfd_fence_get_timeline_name (struct dma_fence *f) {struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); +if (!fence) +return NULL ;return fence->timeline_name; }
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +5 -1
@@ -517,7 +517,9 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev = -kfd_topology_device_by_id (target->pdds[i]->dev->id); +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +continue ;uint32_t caps = topo_dev->node_props.capability; if (!(caps & HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
@@ -1071,6 +1073,8 @@ 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) +continue ; device_info.gpu_id = pdd->dev->id; device_info.exception_status = pdd->exception_status;
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3 -0
@@ -1685,6 +1685,9 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,struct kfd_node *dev;int ret; +if (!pdd) +return -EINVAL ; +if (!drm_file)return -EINVAL ;
Signature · 1 line
2.43.0
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 24 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrew Martin
Sent: Friday, November 14, 2025 9:41 AM
To: [email protected]
Cc: Martin, Andrew <[email protected]>
Subject: [PATCH] drm/amdkfd: FORWARD NULLThis 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_debug.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c static const char *amdkfd_fence_get_driver_name(struct · line 109
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +2
-0@@ -104,6 +104,8 @@ static const char *amdkfd_fence_get_driver_name(struct dma_fence *f)static const char *amdkfd_fence_get_timeline_name (struct dma_fence *f) {struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); +if (!fence) +return NULL ;
Felix can hopefully confirm, but we may need to have something here, since the references here expect something. Like in
#define AMDGPU_JOB_GET_TIMELINE_NAME(job) \
job->base.s_fence->finished.ops->get_timeline_name(&job->base.s_fence->finished)Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0return fence->timeline_name; }drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1@@ -517,7 +517,9 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev = -kfd_topology_device_by_id (target->pdds[i]->dev->id); +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +continue ;uint32_t caps = topo_dev->node_props.capability;if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0@@ -1071,6 +1073,8 @@ 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) +continue ;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 · line 1693
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0@@ -1685,6 +1685,9 @@ int kfd_process_device_init_vm(structkfd_process_device *pdd, struct kfd_node *dev;int ret; +if (!pdd) +return -EINVAL ; +if (!drm_file)return -EINVAL ;
Probably easier to just combine the !pdd and !drm_file into the same check.
Kent
Quoted 3 lines
--
2.43.0
[AMD Official Use Only - AMD Internal Distribution Only]
Greetings @Russell, Kent
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c static const char *amdkfd_fence_get_driver_name(struct dma_fence *f) · line 108
Quoted 3 lines
struct amdgpu_amdkfd_fence *fence = to_amdgpu_amdkfd_fence(f);drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +2
-0+if (!fence) +return NULL ;
Thanks, looking forward to any lessons from this. The main concern for Coverity is use of the pointer without checking first if it is valid.
Felix Kuehling
maintainerQuoted 33 lines · Kent
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 24 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrew Martin
Sent: Friday, November 14, 2025 9:41 AM
To: [email protected]
Cc: Martin, Andrew <[email protected]>
Subject: [PATCH] drm/amdkfd: FORWARD NULLThis 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_debug.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c static const char *amdkfd_fence_get_driver_name(struct · line 109
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +2
-0@@ -104,6 +104,8 @@ static const char *amdkfd_fence_get_driver_name(struct dma_fence *f)static const char *amdkfd_fence_get_timeline_name (struct dma_fence *f) {struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); +if (!fence) +return NULL ;Felix can hopefully confirm, but we may need to have something here, since the references here expect something. Like in
Quoted 2 lines
#define AMDGPU_JOB_GET_TIMELINE_NAME(job) \
job->base.s_fence->finished.ops->get_timeline_name(&job->base.s_fence->finished)For amdgpu Job fences the above makes sense. But KFD fences are our evictions fences. There is no job associated with them.
I don't think the NULL check is needed here. to_amdgpu_amdkfd_fence returns NULL if the f is NULL or the fence is not an amdgpu_amdkfd_fence, based on the fence_ops. But we're in a fence_ops callback here that should only be called for amdgpu_amdkfd_fences.
That said, if you need a check to satisfy a static checker, I suggest this:
return fence ? fence->timeline_name : NULL;
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0return fence->timeline_name; }drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -517,7 +517,9 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) · line 522
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev = -kfd_topology_device_by_id (target->pdds[i]->dev->id); +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +continue ;
This loop checks the capabilities of all the devices. If a device is not found, we should assume the worst and return an error, instead of just assuming that it'll be fine.
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_device_snapshot(struct kfd_process · line 1079
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0uint32_t caps = topo_dev->node_props.capability;if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0@@ -1071,6 +1073,8 @@ 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) +continue ;
I'd return an error here as well, because we obviously don't have accurate device info.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0device_info.gpu_id = pdd->dev->id;device_info.exception_status = pdd->exception_status;drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0@@ -1685,6 +1685,9 @@ int kfd_process_device_init_vm(structkfd_process_device *pdd, struct kfd_node *dev;int ret;
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1690
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+if (!pdd) +return -EINVAL ; +
We generally assume that functions are called with valid parameters. With that argument, we should probably remove the check for !drm_file below as well.
Regards,
Felix
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1692
Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0if (!drm_file)return -EINVAL ;Probably easier to just combine the !pdd and !drm_file into the same check.
Kent
Quoted 2 lines
--
2.43.0
[AMD Official Use Only - AMD Internal Distribution Only]
Greetings @Kuehling, Felix,
Thanks for the review comments, please see some discovery comments in lined! Patch 2 with the suggested fixes is on its way.
Note: I have added 1 change in the new patch (re-running the scan, found it)
file: kfd_crat.c:2360
...
peer_dev = kfd_topology_device_by_proximity_domain_no_lock(nid);
if (!peer_dev)
return -ENODEV;...
Quoted 51 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Friday, November 14, 2025 4:48 PM
To: Russell, Kent <[email protected]>; Martin, Andrew <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdkfd: FORWARD NULLQuoted 20 lines · Kent
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 18 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrew Martin
Sent: Friday, November 14, 2025 9:41 AM
To: [email protected]
Cc: Martin, Andrew <[email protected]>
Subject: [PATCH] drm/amdkfd: FORWARD NULLThis 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_debug.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c static const char · line 110
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +2
-0@@ -104,6 +104,8 @@ static const char *amdkfd_fence_get_driver_name(struct dma_fence *f)static const char *amdkfd_fence_get_timeline_name (struct dma_fence *f) {struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); +if (!fence) +return NULL ;Felix can hopefully confirm, but we may need to have something here, since the references here expect something. Like in #define
AMDGPU_JOB_GET_TIMELINE_NAME(job)\Quoted 3 lines
job->base.s_fence->finished.ops->get_timeline_name(&job->base.s_fence-
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0finished)For amdgpu Job fences the above makes sense. But KFD fences are our evictions fences. There is no job associated with them.
Quoted 8 lines
I don't think the NULL check is needed here.
to_amdgpu_amdkfd_fencereturns NULL if the f is NULL or the fence is not anamdgpu_amdkfd_fence, based on thefence_ops. But we're in afence_opscallback here that should only be called foramdgpu_amdkfd_fences.That said, if you need a check to satisfy a static checker, I suggest this:
return fence ? fence->timeline_name : NULL;
This worked perfectly.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
return fence->timeline_name;}
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -517,7 +517,9 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)
Quoted 11 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) · line 522
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev = -kfd_topology_device_by_id (target->pdds[i]->dev->id); +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +continue ;This loop checks the capabilities of all the devices. If a device is not found, we should assume the worst and return an error, instead of just assuming that it'll be fine.
Done
Quoted 18 lines
Quoted 14 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0uint32_t caps = topo_dev->node_props.capability;if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_device_snapshot(struct · line 1079
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0@@ -1071,6 +1073,8 @@ 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) +continue ;I'd return an error here as well, because we obviously don't have accurate device info.
Done
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0device_info.gpu_id = pdd->dev->id;device_info.exception_status = pdd->exception_status;drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0@@ -1685,6 +1685,9 @@ int kfd_process_device_init_vm(structkfd_process_device *pdd, struct kfd_node *dev;int ret;
Quoted 7 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1690
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+if (!pdd) +return -EINVAL ; +We generally assume that functions are called with valid parameters. With that argument, we should probably remove the check for !drm_file below as well.
Done. This is a good thing to note, but I want to have another lesson here. Is this true in general or only for internal/private APIs? I asked b/c this comment forced me to really look carefully the kfd_process_device_init_vm(), which is prototyped in kfd_priv.h. This mean this and any other function from here should be called with valid params. But public APIs should check that the params are valid, b/c this how we prevent crashes in our library?
Quoted 12 lines
Regards,
FelixQuoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1692
Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0if (!drm_file)return -EINVAL ;Probably easier to just combine the !pdd and !drm_file into the same check.
Kent
Quoted 2 lines
--
2.43.0
Kuehling, Felix
maintainerQuoted 6 lines · Andrew
[AMD Official Use Only - AMD Internal Distribution Only]
Greetings @Kuehling, Felix,
Thanks for the review comments, please see some discovery comments in lined! Patch 2 with the suggested fixes is on its way.
Quoted 7 lines
Note: I have added 1 change in the new patch (re-running the scan, found it)
file: kfd_crat.c:2360
...peer_dev = kfd_topology_device_by_proximity_domain_no_lock(nid); if (!peer_dev) return -ENODEV;
Hmm, not sure I agree with this one. This is in a loop that looks for XGMI-connected peer devices. Currently we create devices with increasing proximity domains and no gaps. So kfd_topology_device_by_proximity_domain_no_lock should never fail. Maybe in some future scenario where a device was hot-unplugged this assumption may be broken.
To be more robust here, I'd just continue if peer_dev is NULL. That way a topology with gaps doesn't cause the creation of new devices to fail.
Quoted 113 lines
...
Quoted 49 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Friday, November 14, 2025 4:48 PM
To: Russell, Kent <[email protected]>; Martin, Andrew <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdkfd: FORWARD NULLQuoted 20 lines · Kent
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 18 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrew Martin
Sent: Friday, November 14, 2025 9:41 AM
To: [email protected]
Cc: Martin, Andrew <[email protected]>
Subject: [PATCH] drm/amdkfd: FORWARD NULLThis 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_debug.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c static const char · line 110
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +2
-0@@ -104,6 +104,8 @@ static const char *amdkfd_fence_get_driver_name(struct dma_fence *f)static const char *amdkfd_fence_get_timeline_name (struct dma_fence *f) {struct amdgpu_amdkfd_fence *fence =to_amdgpu_amdkfd_fence (f); +if (!fence) +return NULL ;Felix can hopefully confirm, but we may need to have something here, since the references here expect something. Like in #define
AMDGPU_JOB_GET_TIMELINE_NAME(job)\Quoted 2 lines
job->base.s_fence->finished.ops->get_timeline_name(&job->base.s_fence-
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0finished)For amdgpu Job fences the above makes sense. But KFD fences are our evictions fences. There is no job associated with them.
Quoted 8 lines
I don't think the NULL check is needed here.
to_amdgpu_amdkfd_fencereturns NULL if the f is NULL or the fence is not anamdgpu_amdkfd_fence, based on thefence_ops. But we're in afence_opscallback here that should only be called foramdgpu_amdkfd_fences.That said, if you need a check to satisfy a static checker, I suggest this:
return fence ? fence->timeline_name : NULL;This worked perfectly.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
return fence->timeline_name;}
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -517,7 +517,9 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)Quoted 10 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) · line 522
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev = -kfd_topology_device_by_id (target->pdds[i]->dev->id); +kfd_topology_device_by_id (target->pdds[i]->dev->id); +if (!topo_dev) +continue ;This loop checks the capabilities of all the devices. If a device is not found, we should assume the worst and return an error, instead of just assuming that it'll be fine.
Done
Quoted 16 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_device_snapshot(struct · line 1079
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0uint32_t caps = topo_dev->node_props.capability;if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0@@ -1071,6 +1073,8 @@ 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) +continue ;I'd return an error here as well, because we obviously don't have accurate device info.
Done
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0device_info.gpu_id = pdd->dev->id;device_info.exception_status = pdd->exception_status;drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0@@ -1685,6 +1685,9 @@ int kfd_process_device_init_vm(structkfd_process_device *pdd, struct kfd_node *dev;int ret;
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1690
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +3
-0+if (!pdd) +return -EINVAL ; +We generally assume that functions are called with valid parameters. With that argument, we should probably remove the check for !drm_file below as well.
Done. This is a good thing to note, but I want to have another lesson here. Is this true in general or only for internal/private APIs? I asked b/c this comment forced me to really look carefully the
kfd_process_device_init_vm(), which is prototyped inkfd_priv.h. This mean this and any other function from here should be called with valid params. But public APIs should check that the params are valid, b/c this how we prevent crashes in our library?
Right, I should have been more precise. Public APIs where you don't know and don't trust the callers need to check their parameters. Internal APIs where you know and trust the callers don't need to do redundant checks.
Regards,
Felix
Quoted 11 lines
Quoted 11 lines
Regards,
FelixQuoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct kfd_process_device *pdd, · line 1692
Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0
-0if (!drm_file)return -EINVAL ;Probably easier to just combine the !pdd and !drm_file into the same check.
Kent
Quoted 2 lines
--
2.43.0