[ofa-general] [PATCH] opensm: osm_node_get_physp_ptr() usage fixes

Sasha Khapyorsky sashak at voltaire.com
Wed May 30 15:01:27 PDT 2007


Function osm_node_get_physp_ptr() cannot return NULL, but can return
pointer to non-initialized object. This patch fixes cases where resulted
pointer was not verified properly.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/opensm/osm_link_mgr.c           |    2 +-
 opensm/opensm/osm_mcast_mgr.c          |    1 -
 opensm/opensm/osm_node.c               |   28 ++++++---------------
 opensm/opensm/osm_node_info_rcv.c      |   41 +++++++++++--------------------
 opensm/opensm/osm_pkey_rcv.c           |    2 -
 opensm/opensm/osm_port.c               |    5 +--
 opensm/opensm/osm_port_info_rcv.c      |    7 ++---
 opensm/opensm/osm_qos.c                |    2 +-
 opensm/opensm/osm_sa_link_record.c     |   19 +++++++-------
 opensm/opensm/osm_sa_pkey_record.c     |    5 +---
 opensm/opensm/osm_sa_portinfo_record.c |    5 +---
 opensm/opensm/osm_sa_slvl_record.c     |    6 ----
 opensm/opensm/osm_sa_vlarb_record.c    |    5 +---
 opensm/opensm/osm_state_mgr.c          |    8 +----
 opensm/opensm/osm_switch.c             |    5 ++-
 opensm/opensm/osm_trap_rcv.c           |    5 +++-
 opensm/opensm/osm_ucast_lash.c         |   12 ++++----
 17 files changed, 58 insertions(+), 100 deletions(-)

diff --git a/opensm/opensm/osm_link_mgr.c b/opensm/opensm/osm_link_mgr.c
index a38d179..73bebce 100644
--- a/opensm/opensm/osm_link_mgr.c
+++ b/opensm/opensm/osm_link_mgr.c
@@ -435,7 +435,7 @@ __osm_link_mgr_process_port(
       specified state.
     */
     p_physp = osm_node_get_physp_ptr( p_port->p_node, (uint8_t)i );
-    if( p_physp && osm_physp_is_valid( p_physp ) )
+    if( osm_physp_is_valid( p_physp ) )
     {
       current_state = osm_physp_get_port_state( p_physp );
 
diff --git a/opensm/opensm/osm_mcast_mgr.c b/opensm/opensm/osm_mcast_mgr.c
index da787b4..2ecb34e 100644
--- a/opensm/opensm/osm_mcast_mgr.c
+++ b/opensm/opensm/osm_mcast_mgr.c
@@ -818,7 +818,6 @@ __osm_mcast_mgr_branch(
       CL_ASSERT( p_remote_node->sw );
 
       p_physp = osm_node_get_physp_ptr( p_node, i );
-      CL_ASSERT( p_physp );
       CL_ASSERT( osm_physp_is_valid( p_physp ) );
 
       p_remote_physp = osm_physp_get_remote( p_physp );
diff --git a/opensm/opensm/osm_node.c b/opensm/opensm/osm_node.c
index cd4ccfa..8d2c3f5 100644
--- a/opensm/opensm/osm_node.c
+++ b/opensm/opensm/osm_node.c
@@ -61,7 +61,6 @@ osm_node_init_physp(
   IN osm_node_t* const p_node,
   IN const osm_madw_t* const p_madw )
 {
-  osm_physp_t        *p_physp;
   ib_net64_t         port_guid;
   ib_smp_t           *p_smp;
   ib_node_info_t     *p_ni;
@@ -80,9 +79,8 @@ osm_node_init_physp(
 
   CL_ASSERT( port_num < p_node->physp_tbl_size );
 
-  p_physp = osm_node_get_physp_ptr( p_node, port_num );
-
-  osm_physp_init( p_physp, port_guid, port_num, p_node,
+  osm_physp_init( &p_node->physp_table[port_num],
+                  port_guid, port_num, p_node,
                   osm_madw_get_bind_handle( p_madw ),
                   p_smp->hop_count, p_smp->initial_path );
 }
@@ -133,7 +131,7 @@ osm_node_new(
       Get(NodeInfo).
     */
     for( i = 0; i < p_node->physp_tbl_size; i++ )
-      osm_physp_construct( osm_node_get_physp_ptr( p_node, i ) );
+      osm_physp_construct( &p_node->physp_table[i] );
 
     osm_node_init_physp( p_node, p_madw );
   }
@@ -147,18 +145,13 @@ static void
 osm_node_destroy(
   IN osm_node_t *p_node )
 {
-  osm_physp_t *p_physp;
   uint16_t i;
 
   /*
     Cleanup all physports 
   */
   for( i = 0; i < p_node->physp_tbl_size; i++ )
-  {
-    p_physp = osm_node_get_physp_ptr( p_node, i );
-    if (p_physp) 
-      osm_physp_destroy( p_physp );
-  }
+    osm_physp_destroy( &p_node->physp_table[i] );
 }
 
 /**********************************************************************
@@ -189,8 +182,7 @@ osm_node_link(
   CL_ASSERT( remote_port_num < p_remote_node->physp_tbl_size );
 
   p_physp = osm_node_get_physp_ptr( p_node, port_num );
-  p_remote_physp =  osm_node_get_physp_ptr( p_remote_node,
-                                            remote_port_num );
+  p_remote_physp =  osm_node_get_physp_ptr( p_remote_node, remote_port_num );
 
   if (p_physp->p_remote_physp)
     p_physp->p_remote_physp->p_remote_physp = NULL;
@@ -220,8 +212,7 @@ osm_node_unlink(
   {
 
     p_physp = osm_node_get_physp_ptr( p_node, port_num );
-    p_remote_physp =  osm_node_get_physp_ptr( p_remote_node,
-                                              remote_port_num );
+    p_remote_physp =  osm_node_get_physp_ptr( p_remote_node, remote_port_num );
 
     osm_physp_unlink( p_physp, p_remote_physp );
   }
@@ -243,8 +234,7 @@ osm_node_link_exists(
   CL_ASSERT( remote_port_num < p_remote_node->physp_tbl_size );
 
   p_physp = osm_node_get_physp_ptr( p_node, port_num );
-  p_remote_physp =  osm_node_get_physp_ptr( p_remote_node,
-                                            remote_port_num );
+  p_remote_physp =  osm_node_get_physp_ptr( p_remote_node, remote_port_num );
 
   return( osm_physp_link_exists( p_physp, p_remote_physp ) );
 }
@@ -265,8 +255,7 @@ osm_node_link_has_valid_ports(
   CL_ASSERT( remote_port_num < p_remote_node->physp_tbl_size );
 
   p_physp = osm_node_get_physp_ptr( p_node, port_num );
-  p_remote_physp =  osm_node_get_physp_ptr( p_remote_node,
-                                            remote_port_num );
+  p_remote_physp =  osm_node_get_physp_ptr( p_remote_node, remote_port_num );
 
   return( osm_physp_is_valid( p_physp ) &&
           osm_physp_is_valid( p_remote_physp ) );
@@ -329,4 +318,3 @@ osm_node_get_remote_base_lid(
 
   return( 0 );
 }
-
diff --git a/opensm/opensm/osm_node_info_rcv.c b/opensm/opensm/osm_node_info_rcv.c
index 2c79056..2486ffb 100644
--- a/opensm/opensm/osm_node_info_rcv.c
+++ b/opensm/opensm/osm_node_info_rcv.c
@@ -144,17 +144,14 @@ __osm_ni_rcv_set_links(
 
             p_physp = osm_node_get_physp_ptr( p_node, port_num );
             sprintf( dr_new_path, "no_path_available" );
-            if (p_physp)
+            p_path = osm_physp_get_dr_path_ptr( p_physp );
+            if ( p_path )
             {
-              p_path = osm_physp_get_dr_path_ptr( p_physp );
-              if ( p_path )
+              sprintf( dr_new_path, "new path:" );
+              for (i = 0; i <= p_path->hop_count; i++ )
               {
-                sprintf( dr_new_path, "new path:" );
-                for (i = 0; i <= p_path->hop_count; i++ )
-                {
-                  sprintf( line, "[%X]", p_path->path[i] );
-                  strcat( dr_new_path, line );
-                }
+                sprintf( line, "[%X]", p_path->path[i] );
+                strcat( dr_new_path, line );
               }
             }
 
@@ -164,17 +161,14 @@ __osm_ni_rcv_set_links(
               p_old_neighbor_node,
               old_neighbor_port_num);
             sprintf( dr_old_path, "no_path_available" );
-            if (p_old_physp)
+            p_old_path = osm_physp_get_dr_path_ptr( p_old_physp );
+            if ( p_old_path )
             {
-              p_old_path = osm_physp_get_dr_path_ptr( p_old_physp );
-              if ( p_old_path )
+              sprintf( dr_old_path, "old_path:" );
+              for (i = 0; i <= p_old_path->hop_count; i++ )
               {
-                sprintf( dr_old_path, "old_path:" );
-                for (i = 0; i <= p_old_path->hop_count; i++ )
-                {
-                  sprintf( line, "[%X]", p_old_path->path[i] );
-                  strcat( dr_old_path, line );
-                }
+                sprintf( line, "[%X]", p_old_path->path[i] );
+                strcat( dr_old_path, line );
               }
             }
 
@@ -226,10 +220,9 @@ __osm_ni_rcv_set_links(
                      cl_ntoh64( osm_node_get_node_guid( p_node ) ),
                      port_num );
             p_physp = osm_node_get_physp_ptr( p_node, port_num );
-            if (p_physp)
-              osm_dump_dr_path(p_rcv->p_log,
-                               osm_physp_get_dr_path_ptr(p_physp),
-                               OSM_LOG_ERROR);
+            osm_dump_dr_path(p_rcv->p_log,
+                             osm_physp_get_dr_path_ptr(p_physp),
+                             OSM_LOG_ERROR);
 
             osm_log( p_rcv->p_log, OSM_LOG_SYS,
                      "Errors on subnet. Duplicate GUID found "
@@ -313,7 +306,6 @@ __osm_ni_rcv_process_new_node(
   */
   p_physp = osm_node_get_physp_ptr( p_node, port_num );
 
-  CL_ASSERT( p_physp );
   CL_ASSERT( osm_physp_is_valid( p_physp ) );
   CL_ASSERT( osm_madw_get_bind_handle( p_madw ) ==
              osm_dr_path_get_bind_handle(
@@ -379,7 +371,6 @@ __osm_ni_rcv_get_node_desc(
   */
   p_physp = osm_node_get_physp_ptr( p_node, port_num );
 
-  CL_ASSERT( p_physp );
   CL_ASSERT( osm_physp_is_valid( p_physp ) );
   CL_ASSERT( osm_madw_get_bind_handle( p_madw ) ==
              osm_dr_path_get_bind_handle(
@@ -539,8 +530,6 @@ __osm_ni_rcv_process_existing_ca_or_router(
   {
     p_physp = osm_node_get_physp_ptr( p_node, port_num );
 
-    CL_ASSERT( p_physp );
-
     if ( !osm_physp_is_valid( p_physp ) )
     {
         osm_log( p_rcv->p_log, OSM_LOG_ERROR,
diff --git a/opensm/opensm/osm_pkey_rcv.c b/opensm/opensm/osm_pkey_rcv.c
index 7c87d7e..67fe067 100644
--- a/opensm/opensm/osm_pkey_rcv.c
+++ b/opensm/opensm/osm_pkey_rcv.c
@@ -174,8 +174,6 @@ osm_pkey_rcv_process(
     port_num = p_physp->port_num;
   }
 
-  CL_ASSERT( p_physp );
-
   /*
     We do not mind if this is a result of a set or get - all we want is to
     update the subnet.
diff --git a/opensm/opensm/osm_port.c b/opensm/opensm/osm_port.c
index eab86e1..9e86ca5 100644
--- a/opensm/opensm/osm_port.c
+++ b/opensm/opensm/osm_port.c
@@ -589,7 +589,7 @@ __osm_physp_get_dr_physp_set(
              p_path->path[hop]);
 
     /* make sure we got a valid port and it has a remote port */
-    if (!(p_physp && osm_physp_is_valid( p_physp )))
+    if (!osm_physp_is_valid( p_physp ))
     {
       osm_log( p_log, OSM_LOG_ERROR,
                "__osm_physp_get_dr_nodes_set: ERR 4104: "
@@ -770,8 +770,7 @@ osm_physp_replace_dr_path_with_alternate_dr_path(
            4. The port is not in the physp_map
            5. This port haven't been visited before
         */
-        if ( p_remote_physp &&
-             osm_physp_is_valid ( p_remote_physp ) &&
+        if ( osm_physp_is_valid ( p_remote_physp ) &&
              p_remote_physp != p_physp &&
              cl_map_get( &physp_map, __osm_ptr_to_key(p_remote_physp)) == NULL &&
              cl_map_get( &visited_map, __osm_ptr_to_key(p_remote_physp)) == NULL )
diff --git a/opensm/opensm/osm_port_info_rcv.c b/opensm/opensm/osm_port_info_rcv.c
index 0076b00..a53044f 100644
--- a/opensm/opensm/osm_port_info_rcv.c
+++ b/opensm/opensm/osm_port_info_rcv.c
@@ -559,7 +559,7 @@ osm_pi_rcv_process_set(
   CL_ASSERT( p_node );
 
   p_physp = osm_node_get_physp_ptr( p_node, port_num );
-  CL_ASSERT( p_physp && osm_physp_is_valid( p_physp ) );
+  CL_ASSERT( osm_physp_is_valid( p_physp ) );
 
   port_guid = osm_physp_get_port_guid( p_physp );
 
@@ -744,10 +744,9 @@ osm_pi_rcv_process(
     }
 
     p_node = p_port->p_node;
-    p_physp = osm_node_get_physp_ptr( p_node, port_num );
-
     CL_ASSERT( p_node );
-    CL_ASSERT( p_physp );
+
+    p_physp = osm_node_get_physp_ptr( p_node, port_num );
 
     /*
       Determine if we encountered a new Physical Port.
diff --git a/opensm/opensm/osm_qos.c b/opensm/opensm/osm_qos.c
index f426241..bbb1608 100644
--- a/opensm/opensm/osm_qos.c
+++ b/opensm/opensm/osm_qos.c
@@ -337,7 +337,7 @@ osm_signal_t osm_qos_setup(osm_opensm_t * p_osm)
 			num_physp = osm_node_get_num_physp(p_node);
 			for (i = 1; i < num_physp; i++) {
 				p_physp = osm_node_get_physp_ptr(p_node, i);
-				if (!p_physp || !osm_physp_is_valid(p_physp))
+				if (!osm_physp_is_valid(p_physp))
 					continue;
 				status =
 				    qos_physp_setup(&p_osm->log, &p_osm->sm.req,
diff --git a/opensm/opensm/osm_sa_link_record.c b/opensm/opensm/osm_sa_link_record.c
index 5e4e35e..81d3877 100644
--- a/opensm/opensm/osm_sa_link_record.c
+++ b/opensm/opensm/osm_sa_link_record.c
@@ -357,7 +357,8 @@ __osm_lr_rcv_get_port_links(
           p_dest_physp = osm_node_get_physp_ptr( p_dest_port->p_node,
                                                  dest_port_num );
           /* both physical ports should be with data */
-          if (p_src_physp && p_dest_physp)
+          if (osm_physp_is_valid(p_src_physp) &&
+              osm_physp_is_valid(p_dest_physp))
             __osm_lr_rcv_get_physp_link( p_rcv, p_lr, p_src_physp,
                                          p_dest_physp, comp_mask,
                                          p_list, p_req_physp );
@@ -377,7 +378,7 @@ __osm_lr_rcv_get_port_links(
         if (port_num < p_src_port->p_node->physp_tbl_size)
         {          
           p_src_physp = osm_node_get_physp_ptr( p_src_port->p_node, port_num );
-          if (p_src_physp)
+          if (osm_physp_is_valid(p_src_physp))
             __osm_lr_rcv_get_physp_link( p_rcv, p_lr, p_src_physp,
                                          NULL, comp_mask, p_list,
                                          p_req_physp );
@@ -389,7 +390,7 @@ __osm_lr_rcv_get_port_links(
         for( port_num = 1; port_num < num_ports; port_num++ )
         {
           p_src_physp = osm_node_get_physp_ptr( p_src_port->p_node, port_num );
-          if (p_src_physp)
+          if (osm_physp_is_valid(p_src_physp))
             __osm_lr_rcv_get_physp_link( p_rcv, p_lr, p_src_physp,
                                          NULL, comp_mask, p_list,
                                          p_req_physp );
@@ -411,9 +412,9 @@ __osm_lr_rcv_get_port_links(
            this couldn't be a relevant record. */
         if (port_num < p_dest_port->p_node->physp_tbl_size )
         {
-          p_dest_physp = osm_node_get_physp_ptr(
-            p_dest_port->p_node, port_num );
-          if (p_dest_physp)
+          p_dest_physp = osm_node_get_physp_ptr( p_dest_port->p_node,
+                                                 port_num );
+          if (osm_physp_is_valid(p_dest_physp))
             __osm_lr_rcv_get_physp_link( p_rcv, p_lr, NULL,
                                          p_dest_physp, comp_mask,
                                          p_list, p_req_physp );
@@ -424,9 +425,9 @@ __osm_lr_rcv_get_port_links(
         num_ports = osm_node_get_num_physp( p_dest_port->p_node );
         for( port_num = 1; port_num < num_ports; port_num++ )
         {
-          p_dest_physp = osm_node_get_physp_ptr(
-            p_dest_port->p_node, port_num );
-          if (p_dest_physp)
+          p_dest_physp = osm_node_get_physp_ptr( p_dest_port->p_node,
+                                                 port_num );
+          if (osm_physp_is_valid(p_dest_physp))
             __osm_lr_rcv_get_physp_link( p_rcv, p_lr, NULL,
                                          p_dest_physp, comp_mask,
                                          p_list, p_req_physp );
diff --git a/opensm/opensm/osm_sa_pkey_record.c b/opensm/opensm/osm_sa_pkey_record.c
index 8a71314..49606bb 100644
--- a/opensm/opensm/osm_sa_pkey_record.c
+++ b/opensm/opensm/osm_sa_pkey_record.c
@@ -254,7 +254,7 @@ __osm_sa_pkey_by_comp_mask(
       p_physp = osm_node_get_physp_ptr( p_port->p_node, port_num );
       /* Check that the p_physp is valid, and that is shares a pkey
          with the p_req_physp. */
-      if( p_physp && osm_physp_is_valid( p_physp ) &&
+      if( osm_physp_is_valid( p_physp ) &&
           (osm_physp_share_pkey(p_rcv->p_log, p_req_physp, p_physp)) )
         __osm_sa_pkey_check_physp( p_rcv, p_physp, p_ctxt );
     }
@@ -273,9 +273,6 @@ __osm_sa_pkey_by_comp_mask(
     for( port_num = 0; port_num < num_ports; port_num++ )
     {
       p_physp = osm_node_get_physp_ptr( p_port->p_node, port_num );
-      if( p_physp == NULL )
-        continue;
-
       if( !osm_physp_is_valid( p_physp ) )
         continue;
 
diff --git a/opensm/opensm/osm_sa_portinfo_record.c b/opensm/opensm/osm_sa_portinfo_record.c
index 74f53d6..a1f3fcb 100644
--- a/opensm/opensm/osm_sa_portinfo_record.c
+++ b/opensm/opensm/osm_sa_portinfo_record.c
@@ -547,7 +547,7 @@ __osm_sa_pir_by_comp_mask(
       p_physp = osm_node_get_physp_ptr( p_port->p_node, p_rcvd_rec->port_num );
       /* Check that the p_physp is valid, and that the p_physp and the
          p_req_physp share a pkey. */
-      if( p_physp && osm_physp_is_valid( p_physp ) &&
+      if( osm_physp_is_valid( p_physp ) &&
           osm_physp_share_pkey(p_rcv->p_log, p_req_physp, p_physp))
         __osm_sa_pir_check_physp( p_rcv, p_physp, p_ctxt );
     }
@@ -557,9 +557,6 @@ __osm_sa_pir_by_comp_mask(
     for( port_num = 0; port_num < num_ports; port_num++ )
     {
       p_physp = osm_node_get_physp_ptr( p_port->p_node, port_num );
-      if( p_physp == NULL )
-        continue;
-
       if( !osm_physp_is_valid( p_physp ) )
         continue;
 
diff --git a/opensm/opensm/osm_sa_slvl_record.c b/opensm/opensm/osm_sa_slvl_record.c
index e40ad61..010f23e 100644
--- a/opensm/opensm/osm_sa_slvl_record.c
+++ b/opensm/opensm/osm_sa_slvl_record.c
@@ -244,9 +244,6 @@ __osm_sa_slvl_by_comp_mask(
 
     for( out_port_num = out_port_start; out_port_num <= out_port_end; out_port_num++ ) {
       p_out_physp = osm_node_get_physp_ptr( p_port->p_node, out_port_num );
-      if( p_out_physp == NULL )
-        continue;
-
       if( !osm_physp_is_valid( p_out_physp ) )
         continue;
 
@@ -257,9 +254,6 @@ __osm_sa_slvl_by_comp_mask(
 #endif
 
         p_in_physp = osm_node_get_physp_ptr( p_port->p_node, in_port_num );
-        if( p_in_physp == NULL )
-          continue;
-
         if( !osm_physp_is_valid( p_in_physp ) )
           continue;
 
diff --git a/opensm/opensm/osm_sa_vlarb_record.c b/opensm/opensm/osm_sa_vlarb_record.c
index a462ee9..8f60d8d 100644
--- a/opensm/opensm/osm_sa_vlarb_record.c
+++ b/opensm/opensm/osm_sa_vlarb_record.c
@@ -258,7 +258,7 @@ __osm_sa_vl_arb_by_comp_mask(
       p_physp = osm_node_get_physp_ptr( p_port->p_node, port_num );
       /* check that the p_physp is valid, and that the requester
          and the p_physp share a pkey. */
-      if( p_physp && osm_physp_is_valid( p_physp ) &&
+      if( osm_physp_is_valid( p_physp ) &&
           osm_physp_share_pkey(p_rcv->p_log, p_req_physp, p_physp) )
         __osm_sa_vl_arb_check_physp( p_rcv, p_physp, p_ctxt );
     }
@@ -277,9 +277,6 @@ __osm_sa_vl_arb_by_comp_mask(
     for( port_num = 0; port_num < num_ports; port_num++ )
     {
       p_physp = osm_node_get_physp_ptr( p_port->p_node, port_num );
-      if( p_physp == NULL )
-        continue;
-
       if( !osm_physp_is_valid( p_physp ) )
         continue;
 
diff --git a/opensm/opensm/osm_state_mgr.c b/opensm/opensm/osm_state_mgr.c
index 46c1cd0..73980b8 100644
--- a/opensm/opensm/osm_state_mgr.c
+++ b/opensm/opensm/osm_state_mgr.c
@@ -925,7 +925,6 @@ __osm_state_mgr_sweep_hop_1(
 
    p_physp = osm_node_get_physp_ptr( p_node, port_num );
 
-   CL_ASSERT( p_physp );
    CL_ASSERT( osm_physp_is_valid( p_physp ) );
 
    p_dr_path = osm_physp_get_dr_path_ptr( p_physp );
@@ -972,9 +971,6 @@ __osm_state_mgr_sweep_hop_1(
       {
          /* go through the port only if the port is not DOWN */
          p_ext_physp = osm_node_get_physp_ptr( p_node, port_num );
-         /* Make sure the physp object exists */
-         if( !p_ext_physp )
-            continue;
          if( ib_port_info_get_port_state( &( p_ext_physp->port_info ) ) >
              IB_LINK_DOWN )
          {
@@ -1119,7 +1115,7 @@ __osm_topology_file_create(
 
             p_physp = osm_node_get_physp_ptr( p_node, cPort );
 
-            if( ( p_physp == NULL ) || ( !osm_physp_is_valid( p_physp ) ) )
+            if( !osm_physp_is_valid( p_physp ) )
                continue;
 
             p_rphysp = p_physp->p_remote_physp;
@@ -1288,7 +1284,7 @@ __osm_state_mgr_report(
       for( port_num = start_port; port_num < num_ports; port_num++ )
       {
          p_physp = osm_node_get_physp_ptr( p_node, port_num );
-         if( ( p_physp == NULL ) || ( !osm_physp_is_valid( p_physp ) ) )
+         if( !osm_physp_is_valid( p_physp ) )
             continue;
 
          osm_log_printf( p_mgr->p_log, OSM_LOG_VERBOSE, "%s : %s : %02X :",
diff --git a/opensm/opensm/osm_switch.c b/opensm/opensm/osm_switch.c
index a79f5cd..2a8d1c2 100644
--- a/opensm/opensm/osm_switch.c
+++ b/opensm/opensm/osm_switch.c
@@ -321,14 +321,15 @@ osm_switch_recommend_path(
 
     if (port_num != OSM_NO_PATH)
     {
+      CL_ASSERT(port_num < num_ports);
+
       p_physp = osm_node_get_physp_ptr(p_sw->p_node, port_num);
       /*
         Don't be too trusting of the current forwarding table!
         Verify that the port number is legal and that the
         LID is reachable through this port.
       */
-      if( (port_num < num_ports )  &&
-          osm_physp_is_valid(p_physp) &&
+      if( osm_physp_is_valid(p_physp) &&
           osm_physp_is_healthy(p_physp) &&
           osm_physp_get_remote(p_physp) )
       {
diff --git a/opensm/opensm/osm_trap_rcv.c b/opensm/opensm/osm_trap_rcv.c
index 309cdd5..c0cab76 100644
--- a/opensm/opensm/osm_trap_rcv.c
+++ b/opensm/opensm/osm_trap_rcv.c
@@ -100,6 +100,7 @@ __get_physp_by_lid_and_num(
 {
   cl_ptr_vector_t *p_vec = &(p_rcv->p_subn->port_lid_tbl);
   osm_port_t *p_port;
+  osm_physp_t *p_physp;
 
   if (lid > cl_ptr_vector_get_size(p_vec))
     return NULL;
@@ -111,7 +112,9 @@ __get_physp_by_lid_and_num(
   if (osm_node_get_num_physp(p_port->p_node) < num)
     return NULL;
 
-  return( osm_node_get_physp_ptr(p_port->p_node, num) );
+  p_physp = osm_node_get_physp_ptr(p_port->p_node, num);
+
+  return osm_physp_is_valid(p_physp) ? p_physp : NULL;
 }
 
 /**********************************************************************
diff --git a/opensm/opensm/osm_ucast_lash.c b/opensm/opensm/osm_ucast_lash.c
index 5d32e89..04f32d5 100644
--- a/opensm/opensm/osm_ucast_lash.c
+++ b/opensm/opensm/osm_ucast_lash.c
@@ -162,7 +162,7 @@ static uint64_t osm_lash_get_switch_guid(IN const osm_switch_t *p_sw)
   uint64_t switch_guid = -1;
   osm_physp_t* p_physp = osm_node_get_physp_ptr(p_sw->p_node, 0);
 
-  if (p_physp && osm_physp_is_valid (p_physp))
+  if (osm_physp_is_valid(p_physp))
     switch_guid = osm_physp_get_port_guid(p_physp);
 
   return switch_guid;
@@ -215,7 +215,7 @@ static uint8_t find_port_from_lid(IN const ib_net16_t lid_no,
 
     p_current_physp = osm_node_get_physp_ptr(p_sw->p_node, i);
 
-    if (p_current_physp && osm_physp_is_valid (p_current_physp)) {
+    if (osm_physp_is_valid(p_current_physp)) {
 
 	p_remote_physp = p_current_physp->p_remote_physp;
 
@@ -1251,10 +1251,10 @@ static void osm_lash_process_switch(lash_t *p_lash, osm_switch_t *p_sw)
 
     p_current_physp = osm_node_get_physp_ptr(p_sw->p_node, i);
 
-    if (osm_physp_is_valid (p_current_physp)) {
+    if (osm_physp_is_valid(p_current_physp)) {
       p_remote_physp = p_current_physp->p_remote_physp;
 
-      if (p_remote_physp && osm_physp_is_valid ( p_remote_physp ) &&
+      if (p_remote_physp && osm_physp_is_valid(p_remote_physp) &&
           p_remote_physp->p_node->sw) {
 	int physical_port_a_num = osm_physp_get_port_num(p_current_physp);
 	int physical_port_b_num = osm_physp_get_port_num(p_remote_physp);
@@ -1342,8 +1342,8 @@ static int discover_network_properties(lash_t *p_lash)
       for (i=1; i<port_count; i++) {
 	  osm_physp_t *p_current_physp = osm_node_get_physp_ptr(p_sw->p_node, i);
 
-	  if (p_current_physp && osm_physp_is_valid (p_current_physp) &&
-	      p_current_physp->p_remote_physp) {
+	  if (osm_physp_is_valid(p_current_physp) &&
+              p_current_physp->p_remote_physp) {
 
 	    ib_port_info_t *p_port_info = &p_current_physp->port_info;
 	    uint8_t port_vl_min = ib_port_info_get_op_vls(p_port_info);
-- 
1.5.2.160.g10a94




More information about the general mailing list