Skip to contentSkip to conversation

RDMA/cm: Delete two redundant condition branches

PATCH Superseded Zhen Lei 3 participants 5 messages May 10, 2021 – May 12, 2021 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

PATCH 1/1 RDMA/cm: Delete two redundant condition branches

The statement of the last "if (xxx)" branch is the same as the "else" branch. Delete it to simplify code.

No functional change.

---
 drivers/infiniband/core/cm.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/infiniband/core/cm.c +0 -4
index 0ead0d223154011..510beb25f5b8a0b 100644
@@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
 			link = &(*link)->rb_right;
 		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
 			link = &(*link)->rb_left;
-		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
-			link = &(*link)->rb_right;
 		else
 			link = &(*link)->rb_right;
 	}
@@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
 			node = node->rb_right;
 		else if (be64_lt(service_id, cm_id_priv->id.service_id))
 			node = node->rb_left;
-		else if (be64_gt(service_id, cm_id_priv->id.service_id))
-			node = node->rb_right;
 		else
 			node = node->rb_right;
 	}
Signature · 1 line
2.26.0.106.g9fadedd
maintainer
#2 lore raw
In reply to Zhen Lei
Quoted 24 lines · Zhen Lei

The statement of the last "if (xxx)" branch is the same as the "else" branch. Delete it to simplify code.

No functional change.

---
 drivers/infiniband/core/cm.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/infiniband/core/cm.c +0 -2
index 0ead0d223154011..510beb25f5b8a0b 100644
@@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
 			link = &(*link)->rb_right;
 		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
 			link = &(*link)->rb_left;
-		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
-			link = &(*link)->rb_right;
 		else
 			link = &(*link)->rb_right;
 	}

drivers/infiniband/core/cm.c static struct cm_id_private *cm_find_listen(struct ib_device *device, · line 703

Quoted 8 lines
drivers/infiniband/core/cm.c +0 -2
@@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
 			node = node->rb_right;
 		else if (be64_lt(service_id, cm_id_priv->id.service_id))
 			node = node->rb_left;
-		else if (be64_gt(service_id, cm_id_priv->id.service_id))
-			node = node->rb_right;
 		else
 			node = node->rb_right;
 	}

I don't like this, if you want to reorganize this function then it should be written in the normal pattern for this kind of comparision

if (a < b)
..
else if (a > b)
..
else // a == b
..

You can see the a==b clause written explicitly above this if ladder:

		if ((cur_cm_id_priv->id.service_mask & service_id) ==
		    (service_mask & cur_cm_id_priv->id.service_id) &&
		    (cm_id_priv->id.device == cur_cm_id_priv->id.device)) {

Which is why the trailing else is just unexectuable code.

Jason

#3 lore raw
Quoted 44 lines · Jason Gunthorpe
Quoted 24 lines · Zhen Lei

The statement of the last "if (xxx)" branch is the same as the "else" branch. Delete it to simplify code.

No functional change.

---
 drivers/infiniband/core/cm.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/infiniband/core/cm.c +0 -2
index 0ead0d223154011..510beb25f5b8a0b 100644
@@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
 			link = &(*link)->rb_right;
 		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
 			link = &(*link)->rb_left;
-		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
-			link = &(*link)->rb_right;
 		else
 			link = &(*link)->rb_right;
 	}

drivers/infiniband/core/cm.c static struct cm_id_private *cm_find_listen(struct ib_device *device, · line 703

Quoted 8 lines
drivers/infiniband/core/cm.c +0 -2
@@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
 			node = node->rb_right;
 		else if (be64_lt(service_id, cm_id_priv->id.service_id))
 			node = node->rb_left;
-		else if (be64_gt(service_id, cm_id_priv->id.service_id))
-			node = node->rb_right;
 		else
 			node = node->rb_right;
 	}

I don't like this, if you want to reorganize this function then it should be written in the normal pattern for this kind of comparision

if (a < b)
..
else if (a > b)
..
else // a == b
..

Quoted 5 lines

You can see the a==b clause written explicitly above this if ladder:

		if ((cur_cm_id_priv->id.service_mask & service_id) ==
		    (service_mask & cur_cm_id_priv->id.service_id) &&
		    (cm_id_priv->id.device == cur_cm_id_priv->id.device)) {

Right,So we'd better rewrite it with this set of judgments. This is because the judgment of (a < b) and (a > b) is performed N times before the judgment of (a == b) is performed. Therefore, the above modification you mentioned can improve the search performance.

Quoted 7 lines

Which is why the trailing else is just unexectuable code.

Jason

.

#4 lore raw
Quoted 49 lines · Leizhen (ThunderTown)
Quoted 46 lines · Jason Gunthorpe
Quoted 24 lines · Zhen Lei

The statement of the last "if (xxx)" branch is the same as the "else" branch. Delete it to simplify code.

No functional change.

---
 drivers/infiniband/core/cm.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/infiniband/core/cm.c +0 -2
index 0ead0d223154011..510beb25f5b8a0b 100644
@@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
 			link = &(*link)->rb_right;
 		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
 			link = &(*link)->rb_left;
-		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
-			link = &(*link)->rb_right;
 		else
 			link = &(*link)->rb_right;
 	}

drivers/infiniband/core/cm.c static struct cm_id_private *cm_find_listen(struct ib_device *device, · line 703

Quoted 8 lines
drivers/infiniband/core/cm.c +0 -2
@@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
 			node = node->rb_right;
 		else if (be64_lt(service_id, cm_id_priv->id.service_id))
 			node = node->rb_left;
-		else if (be64_gt(service_id, cm_id_priv->id.service_id))
-			node = node->rb_right;
 		else
 			node = node->rb_right;
 	}

I don't like this, if you want to reorganize this function then it should be written in the normal pattern for this kind of comparision

if (a < b)
..
else if (a > b)
..
else // a == b
..

You can see the a==b clause written explicitly above this if ladder:

Quoted 8 lines
Quoted 3 lines
		if ((cur_cm_id_priv->id.service_mask & service_id) ==
		    (service_mask & cur_cm_id_priv->id.service_id) &&
		    (cm_id_priv->id.device == cur_cm_id_priv->id.device)) {

Right,So we'd better rewrite it with this set of judgments. This is because the judgment of (a < b) and (a > b) is performed N times before the judgment of (a == b) is performed. Therefore, the above modification you mentioned can improve the search performance.

This modification may have to be patched separately. Combined with one patch, the description is unclear.

Quoted 8 lines
Quoted 8 lines

Which is why the trailing else is just unexectuable code.

Jason

.