drm/amdkfd: Fix warnings from static analyzer Smatch
Subsystems (3)
PATCH 1/1 drm/amdkfd: Fix warnings from static analyzer Smatch
The patch fixes warnings/error as reported by Smatch a static analyzer
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1428 kfd_create_indirect_link_prop() warn: iterator used outside loop: 'cpu_link' drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1462 kfd_create_indirect_link_prop() error: we previously assumed 'cpu_dev' could be null (see line 1420) drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1516 kfd_add_peer_prop() warn: iterator used outside loop: 'iolink3'
--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +17 -17
@@ -1417,15 +1417,15 @@ static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g/* find CPU <--> CPU links */ cpu_dev =kfd_topology_device_by_proximity_domain (i); -if (cpu_dev) { -list_for_each_entry (cpu_link, - &cpu_dev->io_link_props, list) { -if (cpu_link->node_to == gpu_link->node_to) -break ; - } - } +if (!cpu_dev) +continue ; + +list_for_each_entry (cpu_link, &cpu_dev->io_link_props, list) +if (cpu_link->node_to == gpu_link->node_to) +break ; -if (cpu_link->node_to != gpu_link->node_to) +/* Ensures we didn't exit from list search with no hits */ +if (list_entry_is_head (cpu_link, &cpu_dev->io_link_props, list))return -ENOMEM ;/* CPU <--> CPU <--> GPU, GPU node*/
@@ -1510,16 +1510,16 @@ static int kfd_add_peer_prop(struct kfd_topology_device *kdev, cpu_dev =kfd_topology_device_by_proximity_domain (iolink1->node_to);if (cpu_dev) {list_for_each_entry (iolink3, &cpu_dev->io_link_props, list) -if (iolink3->node_to == iolink2->node_to) +if (iolink3->node_to == iolink2->node_to) { + props->weight += iolink3->weight; + props->min_latency += iolink3->min_latency; + props->max_latency += iolink3->max_latency; + props->min_bandwidth =min (props->min_bandwidth, + iolink3->min_bandwidth); + props->max_bandwidth =min (props->max_bandwidth, + iolink3->max_bandwidth);break ; - - props->weight += iolink3->weight; - props->min_latency += iolink3->min_latency; - props->max_latency += iolink3->max_latency; - props->min_bandwidth =min (props->min_bandwidth, - iolink3->min_bandwidth); - props->max_bandwidth =min (props->max_bandwidth, - iolink3->max_bandwidth); + } }else {WARN (1 ,"CPU node not found" ); }
Signature · 1 line
2.35.1
Am 2022-07-06 um 12:47 schrieb Ramesh Errabolu:
Quoted 9 lines
The patch fixes warnings/error as reported by Smatch a static analyzer
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1428kfd_create_indirect_link_prop()warn: iterator used outside loop: 'cpu_link'drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1462kfd_create_indirect_link_prop()error: we previously assumed 'cpu_dev' could be null (see line 1420)drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1516kfd_add_peer_prop()warn: iterator used outside loop: 'iolink3'Fixes 40d6aa758b13 ("drm/amdkfd: Extend KFD device topology to surface peer-to-peer links")Signed-off-by Ramesh Errabolu <[email protected]>Reported-by Dan Carpenter <[email protected]>
Quoted 58 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_topology.c +17
-17@@ -1417,15 +1417,15 @@ static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g/* find CPU <--> CPU links */ cpu_dev =kfd_topology_device_by_proximity_domain (i); -if (cpu_dev) { -list_for_each_entry (cpu_link, - &cpu_dev->io_link_props, list) { -if (cpu_link->node_to == gpu_link->node_to) -break ; - } - } +if (!cpu_dev) +continue ; + +list_for_each_entry (cpu_link, &cpu_dev->io_link_props, list) +if (cpu_link->node_to == gpu_link->node_to) +break ; -if (cpu_link->node_to != gpu_link->node_to) +/* Ensures we didn't exit from list search with no hits */ +if (list_entry_is_head (cpu_link, &cpu_dev->io_link_props, list))return -ENOMEM ;/* CPU <--> CPU <--> GPU, GPU node*/ @@ -1510,16 +1510,16 @@ static int kfd_add_peer_prop(struct kfd_topology_device *kdev, cpu_dev =kfd_topology_device_by_proximity_domain (iolink1->node_to);if (cpu_dev) {list_for_each_entry (iolink3, &cpu_dev->io_link_props, list) -if (iolink3->node_to == iolink2->node_to) +if (iolink3->node_to == iolink2->node_to) { + props->weight += iolink3->weight; + props->min_latency += iolink3->min_latency; + props->max_latency += iolink3->max_latency; + props->min_bandwidth =min (props->min_bandwidth, + iolink3->min_bandwidth); + props->max_bandwidth =min (props->max_bandwidth, + iolink3->max_bandwidth);break ; - - props->weight += iolink3->weight; - props->min_latency += iolink3->min_latency; - props->max_latency += iolink3->max_latency; - props->min_bandwidth =min (props->min_bandwidth, - iolink3->min_bandwidth); - props->max_bandwidth =min (props->max_bandwidth, - iolink3->max_bandwidth); + } }else {WARN (1 ,"CPU node not found" ); }