Skip to content

Commit 09da66f

Browse files
andmar-amdalexdeucher
authored andcommitted
drm/amdkfd: Check for NULL return values
This patch fixes issues when the code moves forward with a potential NULL pointer, without checking. Removed one redundant NULL check for a function parameter. This check is already done in the only caller. Signed-off-by: Andrew Martin <andrew.martin@amd.com> Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent f0157ce commit 09da66f

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static const char *amdkfd_fence_get_timeline_name(struct dma_fence *f)
107107
{
108108
struct amdgpu_amdkfd_fence *fence = to_amdgpu_amdkfd_fence(f);
109109

110-
return fence->timeline_name;
110+
return fence ? fence->timeline_name : NULL;
111111
}
112112

113113
/**

drivers/gpu/drm/amd/amdkfd/kfd_crat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image,
23592359
if (kdev->kfd->hive_id) {
23602360
for (nid = 0; nid < proximity_domain; ++nid) {
23612361
peer_dev = kfd_topology_device_by_proximity_domain_no_lock(nid);
2362-
if (!peer_dev->gpu)
2362+
if (!peer_dev || !peer_dev->gpu)
23632363
continue;
23642364
if (peer_dev->gpu->kfd->hive_id != kdev->kfd->hive_id)
23652365
continue;

drivers/gpu/drm/amd/amdkfd/kfd_debug.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,15 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags)
523523
int i, r = 0, rewind_count = 0;
524524

525525
for (i = 0; i < target->n_pdds; i++) {
526+
uint32_t caps;
527+
uint32_t caps2;
526528
struct kfd_topology_device *topo_dev =
527-
kfd_topology_device_by_id(target->pdds[i]->dev->id);
528-
uint32_t caps = topo_dev->node_props.capability;
529-
uint32_t caps2 = topo_dev->node_props.capability2;
529+
kfd_topology_device_by_id(target->pdds[i]->dev->id);
530+
if (!topo_dev)
531+
return -EINVAL;
532+
533+
caps = topo_dev->node_props.capability;
534+
caps2 = topo_dev->node_props.capability2;
530535

531536
if (!(caps & HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
532537
(*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) {
@@ -1086,6 +1091,10 @@ int kfd_dbg_trap_device_snapshot(struct kfd_process *target,
10861091
for (i = 0; i < tmp_num_devices; i++) {
10871092
struct kfd_process_device *pdd = target->pdds[i];
10881093
struct kfd_topology_device *topo_dev = kfd_topology_device_by_id(pdd->dev->id);
1094+
if (!topo_dev) {
1095+
r = -EINVAL;
1096+
break;
1097+
}
10891098

10901099
device_info.gpu_id = pdd->dev->id;
10911100
device_info.exception_status = pdd->exception_status;

drivers/gpu/drm/amd/amdkfd/kfd_process.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,9 +1773,6 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
17731773
struct kfd_node *dev;
17741774
int ret;
17751775

1776-
if (!drm_file)
1777-
return -EINVAL;
1778-
17791776
if (pdd->drm_priv)
17801777
return -EBUSY;
17811778

0 commit comments

Comments
 (0)