Skip to content

Commit 499839e

Browse files
srishanmalexdeucher
authored andcommitted
drm/amdkfd: Confirm list is non-empty before utilizing list_first_entry in kfd_topology.c
Before using list_first_entry, make sure to check that list is not empty, if list is empty return -ENODATA. Fixes the below: drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1347 kfd_create_indirect_link_prop() warn: can 'gpu_link' even be NULL? drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1428 kfd_add_peer_prop() warn: can 'iolink1' even be NULL? drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1433 kfd_add_peer_prop() warn: can 'iolink2' even be NULL? Fixes: 0f28cca ("drm/amdkfd: Extend KFD device topology to surface peer-to-peer links") Cc: Felix Kuehling <[email protected]> Cc: Christian König <[email protected]> Cc: Alex Deucher <[email protected]> Signed-off-by: Srinivasan Shanmugam <[email protected]> Suggested-by: Felix Kuehling <[email protected]> Suggested-by: Lijo Lazar <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 13a1851 commit 499839e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,11 @@ static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g
13421342
num_cpu++;
13431343
}
13441344

1345+
if (list_empty(&kdev->io_link_props))
1346+
return -ENODATA;
1347+
13451348
gpu_link = list_first_entry(&kdev->io_link_props,
1346-
struct kfd_iolink_properties, list);
1347-
if (!gpu_link)
1348-
return -ENOMEM;
1349+
struct kfd_iolink_properties, list);
13491350

13501351
for (i = 0; i < num_cpu; i++) {
13511352
/* CPU <--> GPU */
@@ -1423,15 +1424,17 @@ static int kfd_add_peer_prop(struct kfd_topology_device *kdev,
14231424
peer->gpu->adev))
14241425
return ret;
14251426

1427+
if (list_empty(&kdev->io_link_props))
1428+
return -ENODATA;
1429+
14261430
iolink1 = list_first_entry(&kdev->io_link_props,
1427-
struct kfd_iolink_properties, list);
1428-
if (!iolink1)
1429-
return -ENOMEM;
1431+
struct kfd_iolink_properties, list);
1432+
1433+
if (list_empty(&peer->io_link_props))
1434+
return -ENODATA;
14301435

14311436
iolink2 = list_first_entry(&peer->io_link_props,
1432-
struct kfd_iolink_properties, list);
1433-
if (!iolink2)
1434-
return -ENOMEM;
1437+
struct kfd_iolink_properties, list);
14351438

14361439
props = kfd_alloc_struct(props);
14371440
if (!props)

0 commit comments

Comments
 (0)