drm/amdkfd: Fix warnings from static analyzer Smatch
Subsystems (3)
PATCH 1/1 drm/amdkfd: Fix warnings from static analyzer Smatch
The patch fixes couple of warnings, 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
Hi Ramesh,
Quoted 8 lines · Ramesh Errabolu
The patch fixes couple of warnings, as reported by Smatch a static analyzer.
Fixes 40d6aa758b13 ("drm/amdkfd: Extend KFD device topology to surface peer-to-peer links")>
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'
Usually, the Fixes tag would go here, after the commit message.
Quoted 3 lines
Signed-off-by Ramesh Errabolu <[email protected]>Reported-by Dan Carpenter <[email protected]>---
As this is a v2 PATCH, it would be nice to have a small changelog here, describing what has changed between the v1 and v2 versions of the patch. Also, you can mark the patch as v2 with git send-email by adding the flag -v2. More on the canonical patch format can be seen in [1].
[1]
https://docs.kernel.org/process/submitting-patches.html#the-canonical-patch-format
Best Regards,
- Maíra Canal
Quoted 57 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" ); }
[AMD Official Use Only - General]
Maira,
Thanks for taking time to review. I understand the request to tag the patch as version 2. However I don't follow your comments on "Fixes" block. Looking at the git log of the branch I see many "Fixes" block that precede the "Signed-off-by" statement.
Could you provide an example.
Regards,
Ramesh
-----Original Message-----
From: Maíra Canal <[email protected]>
Sent: Wednesday, June 29, 2022 6:25 PM
To: Errabolu, Ramesh <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Fix warnings from static analyzer Smatch
[CAUTION: External Email]
Hi Ramesh,
Quoted 11 lines · Ramesh Errabolu
The patch fixes couple of warnings, as reported by Smatch a static analyzer.
Fixes 40d6aa758b13 ("drm/amdkfd: Extend KFD device topology tosurface peer-to-peer links")>
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'
Usually, the Fixes tag would go here, after the commit message.
Quoted 3 lines
Signed-off-by Ramesh Errabolu <[email protected]>Reported-by Dan Carpenter <[email protected]>---
As this is a v2 PATCH, it would be nice to have a small changelog here, describing what has changed between the v1 and v2 versions of the patch. Also, you can mark the patch as v2 with git send-email by adding the flag -v2. More on the canonical patch format can be seen in [1].
Best Regards,
- Maíra Canal
Quoted 62 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 +0
-0@@ -1417,15 +1417,15 @@ static intkfd_create_indirect_link_prop(struct
kfd_topology_device*kdev, int g/* find CPU <--> CPU links */ cpu_dev = kfd_topology_device_by_proximity_domain(i);drivers/gpu/drm/amd/amdkfd/kfd_topology.c +20
-17-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" ); }
Quoted 6 lines · Ramesh
[AMD Official Use Only - General]
Maira,
Thanks for taking time to review. I understand the request to tag the patch as version 2. However I don't follow your comments on "Fixes" block. Looking at the git log of the branch I see many "Fixes" block that precede the "Signed-off-by" statement.
Hi Ramesh,
The canonical patch format is basically, as described by [1]:
<commit message>
...
---
V2 -> V3: Removed redundant helper function
V1 -> V2: Cleaned up coding style and addressed review comments
path/to/file | 5+++--
...
So, on your case, we have the commit message describing the warning reported by Smatch and the error log, then we got the tags. The tags should be in chronological order, so your tags should be:
peer-to-peer links")
See that this canonical format reflects the chronological history of the patch insofar as possible. After the ---, you describe the changes between v1 and v2 in a small changelog.
The documentation linked in [1] explains this in details. So, some examples are exposed in [2], [3] and [4].
[1] https://docs.kernel.org/process/submitting-patches.html
[2]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1db88c5343712e411a2dd45375f27c477e33dc07
[3]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34ad61514c4c3657df21a058f9961c3bb2f84ff2
[4]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d3f2a14b8906df913cb04a706367b012db94a6e8
Best Regards,
- Maíra Canal
Quoted 105 lines
Could you provide an example.
Regards,
Ramesh-----Original Message-----
From: Maíra Canal <[email protected]>
Sent: Wednesday, June 29, 2022 6:25 PM
To: Errabolu, Ramesh <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Fix warnings from static analyzer Smatch[CAUTION: External Email]
Hi Ramesh,
Quoted 11 lines · Ramesh Errabolu
The patch fixes couple of warnings, as reported by Smatch a static analyzer.
Fixes 40d6aa758b13 ("drm/amdkfd: Extend KFD device topology tosurface peer-to-peer links")>
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'Usually, the Fixes tag would go here, after the commit message.
Quoted 3 lines
Signed-off-by Ramesh Errabolu <[email protected]>Reported-by Dan Carpenter <[email protected]>---
As this is a v2 PATCH, it would be nice to have a small changelog here, describing what has changed between the v1 and v2 versions of the patch. Also, you can mark the patch as v2 with git send-email by adding the flag -v2. More on the canonical patch format can be seen in [1].
Best Regards,
- Maíra CanalQuoted 62 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 +0
-0@@ -1417,15 +1417,15 @@ static intkfd_create_indirect_link_prop(struct
kfd_topology_device*kdev, int g/* find CPU <--> CPU links */ cpu_dev = kfd_topology_device_by_proximity_domain(i);drivers/gpu/drm/amd/amdkfd/kfd_topology.c +20
-17-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" ); }