Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1643664 > unrolled thread

[infiniband-hw-i40iw] question about identical code for different branches

Started by"Gustavo A. R. Silva" <garsilva@embeddedor.com>
First post2017-05-18 00:10 +0200
Last post2017-05-19 19:00 +0200
Articles 8 — 6 participants

Back to article view | Back to linux.kernel


Contents

  [infiniband-hw-i40iw] question about identical code for different  branches "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-18 00:10 +0200
    Re: [infiniband-hw-i40iw] question about identical code for  different branches Yuval Shaia <yuval.shaia@oracle.com> - 2017-05-18 08:10 +0200
    Re: [infiniband-hw-i40iw] question about identical code for  different branches Leon Romanovsky <leon@kernel.org> - 2017-05-18 08:40 +0200
      Re: [infiniband-hw-i40iw] question about identical code for  different branches Chien Tin Tung <chien.tin.tung@intel.com> - 2017-05-18 17:10 +0200
    RE: [infiniband-hw-i40iw] question about identical code for  different branches "Saleem, Shiraz" <shiraz.saleem@intel.com> - 2017-05-18 16:40 +0200
      Re: [infiniband-hw-i40iw] question about identical code for  different branches "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-18 20:00 +0200
        [PATCH] infiniband: hw: i40iw: fix duplicated code for different  branches "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-18 20:20 +0200
          Re: [PATCH] infiniband: hw: i40iw: fix duplicated code for different  branches Shiraz Saleem <shiraz.saleem@intel.com> - 2017-05-19 19:00 +0200

#1643664 — [infiniband-hw-i40iw] question about identical code for different branches

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-05-18 00:10 +0200
Subject[infiniband-hw-i40iw] question about identical code for different branches
Message-ID<tIfiO-x8-15@gated-at.bofh.it>
Hello everybody,

While looking into Coverity ID 1362263 I ran into the following piece  
of code at drivers/infiniband/hw/i40iw/i40iw_virtchnl.c:445:

445        if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
446                if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
447                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
448                else
449                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
450                return I40IW_SUCCESS;
451        }

The issue is that lines of code 447 and 449 are identical for  
different branches.

My question here is if one of the branches should be modified, or the  
entire _if_ statement replaced?

Maybe a patch like the following could be applied:

index f4d1368..48fd327 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
@@ -443,10 +443,7 @@ enum i40iw_status_code i40iw_vchnl_recv_pf(struct  
i40iw_sc_dev *dev,
         if (!dev->vchnl_up)
                 return I40IW_ERR_NOT_READY;
         if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
-               if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
-                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
-               else
-                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
+               vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
                 return I40IW_SUCCESS;
         }
         for (iw_vf_idx = 0; iw_vf_idx <  
I40IW_MAX_PE_ENABLED_VF_COUNT; iw_vf_idx++) {

What do you think?

I'd really appreciate any comment on this.

Thank you!
--
Gustavo A. R. Silva

[toc] | [next] | [standalone]


#1643838 — Re: [infiniband-hw-i40iw] question about identical code for different branches

FromYuval Shaia <yuval.shaia@oracle.com>
Date2017-05-18 08:10 +0200
SubjectRe: [infiniband-hw-i40iw] question about identical code for different branches
Message-ID<tImNk-5ZW-5@gated-at.bofh.it>
In reply to#1643664
On Wed, May 17, 2017 at 05:06:54PM -0500, Gustavo A. R. Silva wrote:
> 
> Hello everybody,
> 
> While looking into Coverity ID 1362263 I ran into the following piece of
> code at drivers/infiniband/hw/i40iw/i40iw_virtchnl.c:445:
> 
> 445        if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
> 446                if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
> 447                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> 448                else
> 449                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> 450                return I40IW_SUCCESS;
> 451        }
> 
> The issue is that lines of code 447 and 449 are identical for different
> branches.
> 
> My question here is if one of the branches should be modified, or the entire
> _if_ statement replaced?
> 
> Maybe a patch like the following could be applied:
> 
> index f4d1368..48fd327 100644
> --- a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> +++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> @@ -443,10 +443,7 @@ enum i40iw_status_code i40iw_vchnl_recv_pf(struct
> i40iw_sc_dev *dev,
>         if (!dev->vchnl_up)
>                 return I40IW_ERR_NOT_READY;
>         if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
> -               if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> -               else
> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> +               vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
>                 return I40IW_SUCCESS;
>         }
>         for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT;
> iw_vf_idx++) {
> 
> What do you think?

This looks like a nice catch!

Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>

> 
> I'd really appreciate any comment on this.
> 
> Thank you!
> --
> Gustavo A. R. Silva
> 
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [next] | [standalone]


#1643867 — Re: [infiniband-hw-i40iw] question about identical code for different branches

FromLeon Romanovsky <leon@kernel.org>
Date2017-05-18 08:40 +0200
SubjectRe: [infiniband-hw-i40iw] question about identical code for different branches
Message-ID<tIngm-6dz-27@gated-at.bofh.it>
In reply to#1643664

[Multipart message — attachments visible in raw view] — view raw

On Wed, May 17, 2017 at 05:06:54PM -0500, Gustavo A. R. Silva wrote:
>
> Hello everybody,
>
> While looking into Coverity ID 1362263 I ran into the following piece of
> code at drivers/infiniband/hw/i40iw/i40iw_virtchnl.c:445:
>
> 445        if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
> 446                if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
> 447                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> 448                else
> 449                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> 450                return I40IW_SUCCESS;
> 451        }
>
> The issue is that lines of code 447 and 449 are identical for different
> branches.
>
> My question here is if one of the branches should be modified, or the entire
> _if_ statement replaced?
>
> Maybe a patch like the following could be applied:

It looks like that you can replace I40IW_VCHNL_OP_GET_VER_V0 with
I40IW_VCHNL_OP_GET_VER and get rid of all places with
I40IW_VCHNL_OP_GET_VER_V0.

Thanks

>
> index f4d1368..48fd327 100644
> --- a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> +++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> @@ -443,10 +443,7 @@ enum i40iw_status_code i40iw_vchnl_recv_pf(struct
> i40iw_sc_dev *dev,
>         if (!dev->vchnl_up)
>                 return I40IW_ERR_NOT_READY;
>         if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
> -               if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> -               else
> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> +               vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
>                 return I40IW_SUCCESS;
>         }
>         for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT;
> iw_vf_idx++) {
>
> What do you think?
>
> I'd really appreciate any comment on this.
>
> Thank you!
> --
> Gustavo A. R. Silva
>
>
>
>

[toc] | [prev] | [next] | [standalone]


#1644660 — Re: [infiniband-hw-i40iw] question about identical code for different branches

FromChien Tin Tung <chien.tin.tung@intel.com>
Date2017-05-18 17:10 +0200
SubjectRe: [infiniband-hw-i40iw] question about identical code for different branches
Message-ID<tIvdU-4qH-21@gated-at.bofh.it>
In reply to#1643867
 Thu, May 18, 2017 at 08:00:29AM +0300, Leon Romanovsky wrote:
> On Wed, May 17, 2017 at 05:06:54PM -0500, Gustavo A. R. Silva wrote:
> >
> > Hello everybody,
> >
> > While looking into Coverity ID 1362263 I ran into the following piece of
> > code at drivers/infiniband/hw/i40iw/i40iw_virtchnl.c:445:
> >
> > 445        if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
> > 446                if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
> > 447                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> > 448                else
> > 449                        vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> > 450                return I40IW_SUCCESS;
> > 451        }
> >
> > The issue is that lines of code 447 and 449 are identical for different
> > branches.
> >
> > My question here is if one of the branches should be modified, or the entire
> > _if_ statement replaced?
> >
> > Maybe a patch like the following could be applied:
> 
> It looks like that you can replace I40IW_VCHNL_OP_GET_VER_V0 with
> I40IW_VCHNL_OP_GET_VER and get rid of all places with
> I40IW_VCHNL_OP_GET_VER_V0.

No. I40IW_VCHNL_OP_GET_VER is iw_op_code and I40IW_VCHNL_OP_GET_VER_V0 is
iw_op_ver two different things.

Chien

[toc] | [prev] | [next] | [standalone]


#1644607 — RE: [infiniband-hw-i40iw] question about identical code for different branches

From"Saleem, Shiraz" <shiraz.saleem@intel.com>
Date2017-05-18 16:40 +0200
SubjectRE: [infiniband-hw-i40iw] question about identical code for different branches
Message-ID<tIuKS-3YK-23@gated-at.bofh.it>
In reply to#1643664
> Subject: [infiniband-hw-i40iw] question about identical code for different branches
> 
> 
> index f4d1368..48fd327 100644
> --- a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> +++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> @@ -443,10 +443,7 @@ enum i40iw_status_code i40iw_vchnl_recv_pf(struct
> i40iw_sc_dev *dev,
>          if (!dev->vchnl_up)
>                  return I40IW_ERR_NOT_READY;
>          if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
> -               if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> -               else
> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> +               vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
>                  return I40IW_SUCCESS;
>          }
>          for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT;
> iw_vf_idx++) {
> 
> What do you think?
> 
> I'd really appreciate any comment on this.
> 
Yes. This fix is fine.

Shiraz

[toc] | [prev] | [next] | [standalone]


#1644802 — Re: [infiniband-hw-i40iw] question about identical code for different branches

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-05-18 20:00 +0200
SubjectRe: [infiniband-hw-i40iw] question about identical code for different branches
Message-ID<tIxSq-5YL-1@gated-at.bofh.it>
In reply to#1644607
Quoting "Saleem, Shiraz" <shiraz.saleem@intel.com>:

>> Subject: [infiniband-hw-i40iw] question about identical code for  
>> different branches
>>
>>
>> index f4d1368..48fd327 100644
>> --- a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
>> +++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
>> @@ -443,10 +443,7 @@ enum i40iw_status_code i40iw_vchnl_recv_pf(struct
>> i40iw_sc_dev *dev,
>>          if (!dev->vchnl_up)
>>                  return I40IW_ERR_NOT_READY;
>>          if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
>> -               if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
>> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
>> -               else
>> -                       vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
>> +               vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
>>                  return I40IW_SUCCESS;
>>          }
>>          for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT;
>> iw_vf_idx++) {
>>
>> What do you think?
>>
>> I'd really appreciate any comment on this.
>>
> Yes. This fix is fine.
>

I'll send a patch in a full and proper format shortly.

Thank you all for your comments.
--
Gustavo A. R. Silva

[toc] | [prev] | [next] | [standalone]


#1644820 — [PATCH] infiniband: hw: i40iw: fix duplicated code for different branches

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-05-18 20:20 +0200
Subject[PATCH] infiniband: hw: i40iw: fix duplicated code for different branches
Message-ID<tIybM-6nh-17@gated-at.bofh.it>
In reply to#1644802
Refactor code to avoid identical code for different branches.

Addresses-Coverity-ID: 1357356
Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/infiniband/hw/i40iw/i40iw_virtchnl.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
index f4d1368..48fd327 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
@@ -443,10 +443,7 @@ enum i40iw_status_code i40iw_vchnl_recv_pf(struct i40iw_sc_dev *dev,
 	if (!dev->vchnl_up)
 		return I40IW_ERR_NOT_READY;
 	if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
-		if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
-			vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
-		else
-			vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
+		vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
 		return I40IW_SUCCESS;
 	}
 	for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT; iw_vf_idx++) {
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1645763 — Re: [PATCH] infiniband: hw: i40iw: fix duplicated code for different branches

FromShiraz Saleem <shiraz.saleem@intel.com>
Date2017-05-19 19:00 +0200
SubjectRe: [PATCH] infiniband: hw: i40iw: fix duplicated code for different branches
Message-ID<tITpU-4T3-5@gated-at.bofh.it>
In reply to#1644820
On Thu, May 18, 2017 at 01:11:17PM -0500, Gustavo A. R. Silva wrote:
> Refactor code to avoid identical code for different branches.
> 
> Addresses-Coverity-ID: 1357356
> Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/infiniband/hw/i40iw/i40iw_virtchnl.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> index f4d1368..48fd327 100644
> --- a/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> +++ b/drivers/infiniband/hw/i40iw/i40iw_virtchnl.c
> @@ -443,10 +443,7 @@ enum i40iw_status_code i40iw_vchnl_recv_pf(struct i40iw_sc_dev *dev,
>  	if (!dev->vchnl_up)
>  		return I40IW_ERR_NOT_READY;
>  	if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
> -		if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
> -			vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> -		else
> -			vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
> +		vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
>  		return I40IW_SUCCESS;
>  	}
>  	for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT; iw_vf_idx++) {
> --

Acked-by: Shiraz Saleem <shiraz.saleem@intel.com> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web