IB/core: fix duplicated code for different branches
PATCH 1/1 IB/core: fix duplicated code for different branches
Refactor code to avoid identical code for different branches.
This issue was detected with the help of Coccinelle.
--- drivers/infiniband/core/cm.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/infiniband/core/cm.c +0 -4
@@ -590,8 +590,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; }
@@ -619,8 +617,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.5.0
Quoted 8 lines · Gustavo A. R. Silva
Refactor code to avoid identical code for different branches.
This issue was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <gustavo-L1vi/[email protected]>--- drivers/infiniband/core/cm.c | 4 ---- 1 file changed, 4 deletions(-)
I see that you used the same commit message and title for many patches, it will be better to have description on what exactly you are removing and why there is no bug in that code.
Quoted 15 lines
drivers/infiniband/core/cm.c +0
-2@@ -590,8 +590,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 623
Quoted 5 lines
drivers/infiniband/core/cm.c +0
-2@@ -619,8 +617,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;
You should remove be64_gt() too.
Quoted 6 lines
drivers/infiniband/core/cm.c +0
-1else node = node->rb_right; } --2.5.0
Hi Leon,
Quoted 5 lines · Leon Romanovsky
Quoted 4 lines · Gustavo A. R. Silva
Refactor code to avoid identical code for different branches.
This issue was detected with the help of Coccinelle.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/infiniband/core/cm.c | 4 ---- 1 file changed, 4 deletions(-)I see that you used the same commit message and title for many patches, it will be better to have description on what exactly you are removing and why there is no bug in that code.
Thank you for the suggestion.
I will add a note saying that it is up to the maintainer to verify whether the code is applicable or not.
The intention of the patch is to point out a duplication of code found by a Coccinelle script. I'm also working on similar issues reported by Coverity. It was tested only by compilation as I don't have the proper hardware to test it on.
Quoted 15 lines
Quoted 15 lines
drivers/infiniband/core/cm.c +0
-2@@ -590,8 +590,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; }
Quoted 9 lines
drivers/infiniband/core/cm.c static struct cm_id_private * cm_find_listen(struct ib_device *device, · line 623
Quoted 6 lines
drivers/infiniband/core/cm.c +0
-2@@ -619,8 +617,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;You should remove
be64_gt()too.
Thank you for pointing it out.
Quoted 6 lines
Quoted 6 lines
drivers/infiniband/core/cm.c +0
-1else node = node->rb_right; } --2.5.0
Signature · 1 line
Gustavo A. R. Silva