* Re: [infiniband-hw-i40iw] question about identical code for different branches
2017-05-17 22:06 [infiniband-hw-i40iw] question about identical code for different branches Gustavo A. R. Silva
@ 2017-05-18 5:00 ` Leon Romanovsky
2017-05-18 15:03 ` Chien Tin Tung
2017-05-18 6:00 ` Yuval Shaia
2017-05-18 14:35 ` Saleem, Shiraz
2 siblings, 1 reply; 9+ messages in thread
From: Leon Romanovsky @ 2017-05-18 5:00 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Faisal Latif, Shiraz Saleem, Doug Ledford, Sean Hefty,
Hal Rosenstock, linux-rdma, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1981 bytes --]
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
>
>
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [infiniband-hw-i40iw] question about identical code for different branches
2017-05-18 5:00 ` Leon Romanovsky
@ 2017-05-18 15:03 ` Chien Tin Tung
0 siblings, 0 replies; 9+ messages in thread
From: Chien Tin Tung @ 2017-05-18 15:03 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Gustavo A. R. Silva, Faisal Latif, Shiraz Saleem, Doug Ledford,
Sean Hefty, Hal Rosenstock, linux-rdma, linux-kernel
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [infiniband-hw-i40iw] question about identical code for different branches
2017-05-17 22:06 [infiniband-hw-i40iw] question about identical code for different branches Gustavo A. R. Silva
2017-05-18 5:00 ` Leon Romanovsky
@ 2017-05-18 6:00 ` Yuval Shaia
2017-05-18 14:35 ` Saleem, Shiraz
2 siblings, 0 replies; 9+ messages in thread
From: Yuval Shaia @ 2017-05-18 6:00 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Faisal Latif, Shiraz Saleem, Doug Ledford, Sean Hefty,
Hal Rosenstock, linux-rdma, linux-kernel
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [infiniband-hw-i40iw] question about identical code for different branches
2017-05-17 22:06 [infiniband-hw-i40iw] question about identical code for different branches Gustavo A. R. Silva
2017-05-18 5:00 ` Leon Romanovsky
2017-05-18 6:00 ` Yuval Shaia
@ 2017-05-18 14:35 ` Saleem, Shiraz
2017-05-18 17:54 ` Gustavo A. R. Silva
2 siblings, 1 reply; 9+ messages in thread
From: Saleem, Shiraz @ 2017-05-18 14:35 UTC (permalink / raw)
To: Gustavo A. R. Silva, Latif, Faisal, Doug Ledford, Hefty, Sean,
Hal Rosenstock
Cc: linux-rdma, linux-kernel
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [infiniband-hw-i40iw] question about identical code for different branches
2017-05-18 14:35 ` Saleem, Shiraz
@ 2017-05-18 17:54 ` Gustavo A. R. Silva
2017-05-18 18:11 ` [PATCH] infiniband: hw: i40iw: fix duplicated " Gustavo A. R. Silva
0 siblings, 1 reply; 9+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-18 17:54 UTC (permalink / raw)
To: Saleem, Shiraz
Cc: Latif, Faisal, Doug Ledford, Hefty, Sean, Hal Rosenstock,
linux-rdma, linux-kernel
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] infiniband: hw: i40iw: fix duplicated code for different branches
2017-05-18 17:54 ` Gustavo A. R. Silva
@ 2017-05-18 18:11 ` Gustavo A. R. Silva
2017-05-19 16:59 ` Shiraz Saleem
2017-06-01 22:27 ` Doug Ledford
0 siblings, 2 replies; 9+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-18 18:11 UTC (permalink / raw)
To: Faisal Latif, Shiraz Saleem, Doug Ledford, Sean Hefty, Hal Rosenstock
Cc: linux-rdma, linux-kernel, Yuval Shaia, Gustavo A. R. Silva
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] infiniband: hw: i40iw: fix duplicated code for different branches
2017-05-18 18:11 ` [PATCH] infiniband: hw: i40iw: fix duplicated " Gustavo A. R. Silva
@ 2017-05-19 16:59 ` Shiraz Saleem
2017-06-01 22:27 ` Doug Ledford
1 sibling, 0 replies; 9+ messages in thread
From: Shiraz Saleem @ 2017-05-19 16:59 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Faisal Latif, Doug Ledford, Sean Hefty, Hal Rosenstock,
linux-rdma, linux-kernel, Yuval Shaia
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>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] infiniband: hw: i40iw: fix duplicated code for different branches
2017-05-18 18:11 ` [PATCH] infiniband: hw: i40iw: fix duplicated " Gustavo A. R. Silva
2017-05-19 16:59 ` Shiraz Saleem
@ 2017-06-01 22:27 ` Doug Ledford
1 sibling, 0 replies; 9+ messages in thread
From: Doug Ledford @ 2017-06-01 22:27 UTC (permalink / raw)
To: Gustavo A. R. Silva, Faisal Latif, Shiraz Saleem, Sean Hefty,
Hal Rosenstock
Cc: linux-rdma, linux-kernel, Yuval Shaia
On Thu, 2017-05-18 at 13:11 -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>
Thanks, applied.
--
Doug Ledford <dledford@redhat.com>
GPG KeyID: B826A3330E572FDD
Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
^ permalink raw reply [flat|nested] 9+ messages in thread