diff mbox series

[ibsim,15/23] sim_mad.c: Fix a CONSTANT_EXPRESSION_RESULT for switch_lookup

Message ID 20190102131318.5765-15-honli@redhat.com (mailing list archive)
State Not Applicable
Headers show
Series [ibsim,01/23] move sim_cmd_file into ibsim/sim_cmd.c | expand

Commit Message

Honggang LI Jan. 2, 2019, 1:13 p.m. UTC
Issue was detected by Coverity.

"(outport = node->sw->fdb[lid]) < 0" is always false regardless of
the values of its operands, because node->sw->fdb[lid] is uint8_t.

Signed-off-by: Honggang Li <honli@redhat.com>
---
 ibsim/sim_mad.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Hal Rosenstock Jan. 4, 2019, 12:24 p.m. UTC | #1
On 1/2/2019 8:13 AM, Honggang Li wrote:
> Issue was detected by Coverity.
> 
> "(outport = node->sw->fdb[lid]) < 0" is always false regardless of
> the values of its operands, because node->sw->fdb[lid] is uint8_t.
> 
> Signed-off-by: Honggang Li <honli@redhat.com>
> ---
>  ibsim/sim_mad.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/ibsim/sim_mad.c b/ibsim/sim_mad.c
> index b6e24881fb9e..5ef1d0a6dbeb 100644
> --- a/ibsim/sim_mad.c
> +++ b/ibsim/sim_mad.c
> @@ -1579,12 +1579,11 @@ static int switch_lookup(Node * node, int lid)
>  	if (!node->sw)
>  		return -1;
>  
> -	if (lid > node->sw->linearFDBtop || (outport = node->sw->fdb[lid]) < 0) {
> +	if (lid > node->sw->linearFDBtop) {

Same comment as patch 11/23.

This is not the proper fix. I think that the check should be == 0xff
rather than < 0 or eliminated as in this patch since fdb is initialized
to 0xff (no port for LID).

-- Hal

>  		IBWARN("sw guid %" PRIx64 ": bad lid %u", node->nodeguid, lid);
>  		return -1;
>  	}
> -
> -	return outport;
> +	return outport = node->sw->fdb[lid];
>  }
>  
>  static int port_get_remote(Port * port, Node ** remotenode, Port ** remoteport)
>
Honggang LI Jan. 4, 2019, 2:35 p.m. UTC | #2
On Fri, Jan 04, 2019 at 07:24:34AM -0500, Hal Rosenstock wrote:
> On 1/2/2019 8:13 AM, Honggang Li wrote:
> > Issue was detected by Coverity.
> > 
> > "(outport = node->sw->fdb[lid]) < 0" is always false regardless of
> > the values of its operands, because node->sw->fdb[lid] is uint8_t.
> > 
> > Signed-off-by: Honggang Li <honli@redhat.com>
> > ---
> >  ibsim/sim_mad.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/ibsim/sim_mad.c b/ibsim/sim_mad.c
> > index b6e24881fb9e..5ef1d0a6dbeb 100644
> > --- a/ibsim/sim_mad.c
> > +++ b/ibsim/sim_mad.c
> > @@ -1579,12 +1579,11 @@ static int switch_lookup(Node * node, int lid)
> >  	if (!node->sw)
> >  		return -1;
> >  
> > -	if (lid > node->sw->linearFDBtop || (outport = node->sw->fdb[lid]) < 0) {
> > +	if (lid > node->sw->linearFDBtop) {
> 
> Same comment as patch 11/23.
> 
> This is not the proper fix. I think that the check should be == 0xff

Yes, you are right. Please fix it as 11/23.

> rather than < 0 or eliminated as in this patch since fdb is initialized
> to 0xff (no port for LID).
> 
> -- Hal
> 
> >  		IBWARN("sw guid %" PRIx64 ": bad lid %u", node->nodeguid, lid);
> >  		return -1;
> >  	}
> > -
> > -	return outport;
> > +	return outport = node->sw->fdb[lid];
> >  }
> >  
> >  static int port_get_remote(Port * port, Node ** remotenode, Port ** remoteport)
> >
diff mbox series

Patch

diff --git a/ibsim/sim_mad.c b/ibsim/sim_mad.c
index b6e24881fb9e..5ef1d0a6dbeb 100644
--- a/ibsim/sim_mad.c
+++ b/ibsim/sim_mad.c
@@ -1579,12 +1579,11 @@  static int switch_lookup(Node * node, int lid)
 	if (!node->sw)
 		return -1;
 
-	if (lid > node->sw->linearFDBtop || (outport = node->sw->fdb[lid]) < 0) {
+	if (lid > node->sw->linearFDBtop) {
 		IBWARN("sw guid %" PRIx64 ": bad lid %u", node->nodeguid, lid);
 		return -1;
 	}
-
-	return outport;
+	return outport = node->sw->fdb[lid];
 }
 
 static int port_get_remote(Port * port, Node ** remotenode, Port ** remoteport)