[openib-general] [PATCH] opensm: add check for not intialized pkey blocks

Sasha Khapyorsky sashak at voltaire.com
Wed Jun 21 05:49:27 PDT 2006


Hi Hal,

The lower block of pkey tables' 'blocks' vector may be not initialized
due to lost MADs. We need to check it for NULL. Some duplicated code
removal as well.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---

 osm/opensm/osm_pkey.c |   33 +++++++++++----------------------
 1 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/osm/opensm/osm_pkey.c b/osm/opensm/osm_pkey.c
index 8166c90..caefe18 100644
--- a/osm/opensm/osm_pkey.c
+++ b/osm/opensm/osm_pkey.c
@@ -76,16 +76,19 @@ void osm_pkey_tbl_construct( 
 void osm_pkey_tbl_destroy( 
   IN osm_pkey_tbl_t *p_pkey_tbl)
 {
+  ib_pkey_table_t *p_block;
   uint16_t num_blocks, i;
 
   num_blocks = (uint16_t)(cl_ptr_vector_get_size( &p_pkey_tbl->blocks ));
   for (i = 0; i < num_blocks; i++)
-    free(cl_ptr_vector_get( &p_pkey_tbl->blocks, i ));
+    if ((p_block = cl_ptr_vector_get( &p_pkey_tbl->blocks, i )))
+      free(p_block);
   cl_ptr_vector_destroy( &p_pkey_tbl->blocks );
 
   num_blocks = (uint16_t)(cl_ptr_vector_get_size( &p_pkey_tbl->new_blocks ));
   for (i = 0; i < num_blocks; i++)
-    free(cl_ptr_vector_get( &p_pkey_tbl->new_blocks, i ));
+    if ((p_block = cl_ptr_vector_get( &p_pkey_tbl->new_blocks, i )))
+      free(p_block);
   cl_ptr_vector_destroy( &p_pkey_tbl->new_blocks );
 
   cl_map_remove_all( &p_pkey_tbl->keys );
@@ -112,26 +115,12 @@ osm_pkey_tbl_init(
 void osm_pkey_tbl_init_new_blocks(
   IN const osm_pkey_tbl_t *p_pkey_tbl)
 {
-  ib_pkey_table_t *p_block, *p_new_block;
-  int16_t b, num_blocks, new_blocks;
+  ib_pkey_table_t *p_block;
+  int16_t b, num_blocks = cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks);
 
-  num_blocks = cl_ptr_vector_get_size(&p_pkey_tbl->blocks);
-  new_blocks = cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks);
-
-  for (b = 0; b < num_blocks; b++) {
-    p_block = cl_ptr_vector_get(&p_pkey_tbl->blocks, b);
-    if ( b < new_blocks )
-      p_new_block = cl_ptr_vector_get(&p_pkey_tbl->new_blocks, b);
-    else
-    {
-      p_new_block = (ib_pkey_table_t *)malloc(sizeof(*p_new_block));
-      if (!p_new_block)
-        break;
-      cl_ptr_vector_set(&((osm_pkey_tbl_t *)p_pkey_tbl)->new_blocks, 
-			b, p_new_block);
-    }
-    memset(p_new_block, 0, sizeof(*p_new_block));
-  }
+  for (b = 0; b < num_blocks; b++)
+    if ((p_block = cl_ptr_vector_get(&p_pkey_tbl->new_blocks, b)))
+      memset(p_block, 0, sizeof(*p_block));
 }
 
 /**********************************************************************
@@ -296,7 +285,7 @@ osm_pkey_find_next_free_entry(
   OUT uint8_t       *p_pkey_idx)
 {
   ib_pkey_table_t *p_new_block;
-	
+
   CL_ASSERT(p_block_idx);
   CL_ASSERT(p_pkey_idx);
 




More information about the general mailing list