Skip to contentSkip to conversation

drm/amdkfd: Fix warnings from static analyzer Smatch

PATCH In review Ramesh Errabolu 3 participants 8 messages Jun 28, 2022 – Jun 29, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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/amdkfd/kfd_topology.c | 36 ++++++++++++-----------
 1 file changed, 19 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +19 -17
index 25990bec600d..9d7b9ad70bc8 100644
@@ -1417,15 +1417,17 @@ 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;
+
+		cpu_link = NULL;
+		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) ||
+			(cpu_link->node_to != gpu_link->node_to))
 			return -ENOMEM;
 
 		/* CPU <--> CPU <--> GPU, GPU node*/
@@ -1510,16 +1512,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
maintainer
#1 lore raw

Am 2022-06-28 um 19:25 schrieb Ramesh Errabolu:

Quoted 18 lines

The patch fixes couple of warnings, as reported by Smatch a static analyzer

---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 36 ++++++++++++-----------
  1 file changed, 19 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -1
index 25990bec600d..9d7b9ad70bc8 100644
@@ -1417,15 +1417,17 @@ 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) {

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1423

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -6
-			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;
+
+		cpu_link = NULL;

This initialization is unnecessary. list_for_each_entry will always initialize it.

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1430

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6 -1
+		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) ||
+			(cpu_link->node_to != gpu_link->node_to))

The second condition is redundant. If the list entry is not the head, the node_to must have already matched in the loop.

But I'm no sure this solution is going to satisfy the static checker. It objects to using the iterator (cpu_link) outside the loop. I think a proper solution, that doesn't make any assumptions about how list_for_each_entry is implemented, would be to declare a separate variable as the iterator, and assign cpu_link in the loop only if there is a match.

Regards,
  Felix

Quoted 29 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -9
  			return -ENOMEM;
 
  		/* CPU <--> CPU <--> GPU, GPU node*/
@@ -1510,16 +1512,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");
  		}
#2 lore raw

[AMD Official Use Only - General]

My responses are inline

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, June 28, 2022 6:41 PM
To: Errabolu, Ramesh <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Fix warnings from static analyzer Smatch

Am 2022-06-28 um 19:25 schrieb Ramesh Errabolu:

Quoted 20 lines

The patch fixes couple of warnings, as reported by Smatch a static analyzer

---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 36 ++++++++++++-----------
  1 file changed, 19 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
index 25990bec600d..9d7b9ad70bc8 100644
@@ -1417,15 +1417,17 @@ 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);
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -1
-		if (cpu_dev) {

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1423

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -6
-			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;
+
+		cpu_link = NULL;

This initialization is unnecessary. list_for_each_entry will always initialize it.

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1430

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6 -1
+		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) ||
+			(cpu_link->node_to != gpu_link->node_to))

The second condition is redundant. If the list entry is not the head, the node_to must have already matched in the loop.

Ramesh: Syntactically, it is possible to walk down the list without having the hit. The check list_entry_is_head() is for that scenario.

But I'm no sure this solution is going to satisfy the static checker. It objects to using the iterator (cpu_link) outside the loop. I think a proper solution, that doesn't make any assumptions about how list_for_each_entry is implemented, would be to declare a separate variable as the iterator, and assign cpu_link in the loop only if there is a match.

Ramesh: Will wait for a response from Dan.

Regards,
  Felix

Quoted 29 lines

return -ENOMEM;

/* CPU <--> CPU <--> GPU, GPU node*/

drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -9
@@ -1510,16 +1512,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");
  		}
maintainer
#3 lore raw

Am 2022-06-28 um 20:03 schrieb Errabolu, Ramesh:

Quoted 49 lines

[AMD Official Use Only - General]

My responses are inline

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, June 28, 2022 6:41 PM
To: Errabolu, Ramesh <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Fix warnings from static analyzer Smatch

Am 2022-06-28 um 19:25 schrieb Ramesh Errabolu:

Quoted 20 lines

The patch fixes couple of warnings, as reported by Smatch a static analyzer

---
   drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 36 ++++++++++++-----------
   1 file changed, 19 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
index 25990bec600d..9d7b9ad70bc8 100644
@@ -1417,15 +1417,17 @@ 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);
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -1
-		if (cpu_dev) {

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1423

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -6
-			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;
+
+		cpu_link = NULL;

This initialization is unnecessary. list_for_each_entry will always initialize it.

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
+		list_for_each_entry(cpu_link, &cpu_dev->io_link_props, list)
+			if (cpu_link->node_to == gpu_link->node_to)
+				break;
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1430

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -1
-		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) ||
+			(cpu_link->node_to != gpu_link->node_to))

The second condition is redundant. If the list entry is not the head, the node_to must have already matched in the loop.

Ramesh: Syntactically, it is possible to walk down the list without having the hit. The check list_entry_is_head() is for that scenario.

If you traverse the whole list without a hit, list_entry_is_head will be true. That is also the only case where cpu_link->node_to != gpu_link->node_to is possible. Therefore that condition is redundant. Just checking list_entry_is_head is sufficient.

That said, as I pointed out below, you're still using cpu_link outside the loop. Therefore it's likely the static checker is still going to complain.

Regards,
  Felix

Quoted 43 lines

But I'm no sure this solution is going to satisfy the static checker. It objects to using the iterator (cpu_link) outside the loop. I think a proper solution, that doesn't make any assumptions about how list_for_each_entry is implemented, would be to declare a separate variable as the iterator, and assign cpu_link in the loop only if there is a match.

Ramesh: Will wait for a response from Dan.

Regards,
  Felix

Quoted 29 lines
   			return -ENOMEM;
   
   		/* CPU <--> CPU <--> GPU, GPU node*/
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -9
@@ -1510,16 +1512,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");
   		}
#4 lore raw

[AMD Official Use Only - General]

Will post updated patch. My responses inline below

Regards,
Ramesh

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Wednesday, June 29, 2022 8:58 AM
To: Errabolu, Ramesh <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Fix warnings from static analyzer Smatch

Am 2022-06-28 um 20:03 schrieb Errabolu, Ramesh:

Quoted 51 lines

[AMD Official Use Only - General]

My responses are inline

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, June 28, 2022 6:41 PM
To: Errabolu, Ramesh <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Fix warnings from static analyzer Smatch

Am 2022-06-28 um 19:25 schrieb Ramesh Errabolu:

Quoted 20 lines

The patch fixes couple of warnings, as reported by Smatch a static analyzer

---
   drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 36 ++++++++++++-----------
   1 file changed, 19 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
index 25990bec600d..9d7b9ad70bc8 100644
@@ -1417,15 +1417,17 @@ 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);
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -1
-		if (cpu_dev) {

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1423

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -6
-			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;
+
+		cpu_link = NULL;

This initialization is unnecessary. list_for_each_entry will always initialize it.

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
+		list_for_each_entry(cpu_link, &cpu_dev->io_link_props, list)
+			if (cpu_link->node_to == gpu_link->node_to)
+				break;
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1430

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -1
-		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) ||
+			(cpu_link->node_to != gpu_link->node_to))

The second condition is redundant. If the list entry is not the head, the node_to must have already matched in the loop.

Ramesh: Syntactically, it is possible to walk down the list without having the hit. The check list_entry_is_head() is for that scenario.

If you traverse the whole list without a hit, list_entry_is_head will be true. That is also the only case where cpu_link->node_to != gpu_link->node_to is possible. Therefore that condition is redundant. Just checking list_entry_is_head is sufficient.

Ramesh: You are right, check for list head is sufficient as it implies all cpu_link objects do not pass the test of (cpu_link->node_to == gpu_link->node_to).

That said, as I pointed out below, you're still using cpu_link outside the loop. Therefore it's likely the static checker is still going to complain.

Ramesh: I suspect the reason static analyzer was complaining about cpu_link is because it was being used in the loop conditionally. The new code uses cpu_link in the loop unconditionally. Per this logic it must be valid once we cross the list_entry_is head statement.

Regards,
  Felix

Quoted 43 lines

But I'm no sure this solution is going to satisfy the static checker. It objects to using the iterator (cpu_link) outside the loop. I think a proper solution, that doesn't make any assumptions about how list_for_each_entry is implemented, would be to declare a separate variable as the iterator, and assign cpu_link in the loop only if there is a match.

Ramesh: Will wait for a response from Dan.

Regards,
  Felix

Quoted 29 lines
   			return -ENOMEM;
   
   		/* CPU <--> CPU <--> GPU, GPU node*/ @@ -1510,16 +1512,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)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -9
-				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");
   		}
#5 lore raw
In reply to Felix Kuehling
Quoted 45 lines · Felix Kuehling

Am 2022-06-28 um 19:25 schrieb Ramesh Errabolu:

Quoted 17 lines

The patch fixes couple of warnings, as reported by Smatch a static analyzer

---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 36 ++++++++++++-----------
  1 file changed, 19 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -1
index 25990bec600d..9d7b9ad70bc8 100644
@@ -1417,15 +1417,17 @@ 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) {

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1422

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -6
-			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;
+
+		cpu_link = NULL;

This initialization is unnecessary. list_for_each_entry will always initialize it.

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int kfd_create_indirect_link_prop(struct kfd_topology_device *kdev, int g · line 1430

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6 -1
+		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) ||
+			(cpu_link->node_to != gpu_link->node_to))

The second condition is redundant. If the list entry is not the head, the node_to must have already matched in the loop.

Quoted 5 lines

But I'm no sure this solution is going to satisfy the static checker. It objects to using the iterator (cpu_link) outside the loop. I think a proper solution, that doesn't make any assumptions about how list_for_each_entry is implemented, would be to declare a separate variable as the iterator, and assign cpu_link in the loop only if there is a match.

This patch will silence the Smatch warning. Smatch is can parse the code well enough to know that:

	list_entry_is_head(cpu_link, &cpu_dev->io_link_props, list)

and:

	cpu_link->node_to != gpu_link->node_to

are equivalent. Or actually it's the reverses which are equivalent. If the cpu_link is at list_head then we can't know if they're equal or not
but if it's not a list_head then they must be equal. Ugh...
Complicated to explain in English but easy to see in code. If add some Smatch debug code:

#include "/home/dcarpenter/smatch/check_debug.h"

...

		if (!list_entry_is_head(cpu_link, &cpu_dev->io_link_props, list))
			__smatch_compare(cpu_link->node_to, gpu_link->node_to);

Then it will display that:

drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1431 kfd_create_indirect_link_prop() cpu_link->node_to == gpu_link->node_to

*happy face* Smatch knows that they are ==.

But your review comments are correct. These days we prefer to just use another pointer:

	found = NULL;

	list_for_each_entry() {
		if (entry == correct){
			found = entry;
			break;
		}
	}
	if (!found)
		return -ENODEV;

regards,
dan carpenter

#7 lore raw

[AMD Official Use Only - General]

Thanks for running Smatch on the patch.

Will update the commit message with the list of warnings/errors pointed out by Smatch. Will post the updated patch shortly.

Regards,
Ramesh

-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Wednesday, June 29, 2022 11:13 AM
To: Errabolu, Ramesh <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/amdkfd: Fix warnings from static analyzer Smatch

[CAUTION: External Email]

Quoted 3 lines · Ramesh Errabolu

The patch fixes couple of warnings, as reported by Smatch a static analyzer

I had forgotten what the warnings were. Could you put that in the commit message or describe the bug somehow?

Quoted 2 lines

This needs a Fixes tag as well.

regards,
dan carpenter