[ofa-general] [PATCHv2] opensm: osm_dr_path_extend can fail due to invalid hop count

Hal Rosenstock hnrose at comcast.net
Sun Aug 2 08:31:33 PDT 2009


Change routine to return success/failure status rather than
depend on debug assert
Also, fix callers of this routine to handle this return status

Signed-off-by: Hal Rosenstock <hal.rosenstock at gmail.com>
---
Changes since v1:
Make osm_dr_path_extend return int rather than boolean

diff --git a/opensm/include/opensm/osm_path.h b/opensm/include/opensm/osm_path.h
index 8d65d2c..d02576b 100644
--- a/opensm/include/opensm/osm_path.h
+++ b/opensm/include/opensm/osm_path.h
@@ -2,6 +2,7 @@
  * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
+ * Copyright (c) 2009 HNR Consulting. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -188,15 +189,18 @@ osm_dr_path_init(IN osm_dr_path_t * const p_path,
 *
 * SYNOPSIS
 */
-static inline void
+static inline int
 osm_dr_path_extend(IN osm_dr_path_t * const p_path, IN const uint8_t port_num)
 {
 	p_path->hop_count++;
-	CL_ASSERT(p_path->hop_count < IB_SUBNET_PATH_HOPS_MAX);
+
+	if (p_path->hop_count >= IB_SUBNET_PATH_HOPS_MAX)
+		return -1;
 	/*
 	   Location 0 in the path array is reserved per IB spec.
 	 */
 	p_path->path[p_path->hop_count] = port_num;
+	return 0;
 }
 
 /*
@@ -208,7 +212,7 @@ osm_dr_path_extend(IN osm_dr_path_t * const p_path, IN const uint8_t port_num)
 *		[in] Additional port to add to the DR path.
 *
 * RETURN VALUE
-*	None.
+*	Boolean indicating whether or not path was extended.
 *
 * NOTES
 *
diff --git a/opensm/opensm/osm_node_info_rcv.c b/opensm/opensm/osm_node_info_rcv.c
index bfa5b1f..c454d02 100644
--- a/opensm/opensm/osm_node_info_rcv.c
+++ b/opensm/opensm/osm_node_info_rcv.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2008 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
+ * Copyright (c) 2009 HNR Consulting. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -85,7 +86,10 @@ static void report_duplicated_guid(IN osm_sm_t * sm, osm_physp_t * p_physp,
 			 OSM_LOG_ERROR);
 
 	path = *osm_physp_get_dr_path_ptr(p_new);
-	osm_dr_path_extend(&path, port_num);
+	if (osm_dr_path_extend(&path, port_num))
+		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D05: "
+			"DR path with hop count %d couldn't be extended\n",
+			path.hop_count);
 	osm_dump_dr_path(sm->p_log, &path, OSM_LOG_ERROR);
 
 	osm_log(sm->p_log, OSM_LOG_SYS,
@@ -100,7 +104,12 @@ static void requery_dup_node_info(IN osm_sm_t * sm, osm_physp_t * p_physp,
 	cl_status_t status;
 
 	path = *osm_physp_get_dr_path_ptr(p_physp->p_remote_physp);
-	osm_dr_path_extend(&path, p_physp->p_remote_physp->port_num);
+	if (osm_dr_path_extend(&path, p_physp->p_remote_physp->port_num)) {
+		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0D08: "
+			"DR path with hop count %d couldn't be extended\n",
+			path.hop_count);
+		return;
+	}
 
 	context.ni_context.node_guid =
 	    p_physp->p_remote_physp->p_node->node_info.port_guid;
diff --git a/opensm/opensm/osm_port_info_rcv.c b/opensm/opensm/osm_port_info_rcv.c
index 7b6fb1a..57cc494 100644
--- a/opensm/opensm/osm_port_info_rcv.c
+++ b/opensm/opensm/osm_port_info_rcv.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2008 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
+ * Copyright (c) 2009 HNR Consulting. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -246,9 +247,15 @@ static void pi_rcv_process_switch_port(IN osm_sm_t * sm, IN osm_node_t * p_node,
 			    osm_physp_get_port_num(p_physp)) {
 				path = *osm_physp_get_dr_path_ptr(p_physp);
 
-				osm_dr_path_extend(&path,
-						   osm_physp_get_port_num
-						   (p_physp));
+				if (osm_dr_path_extend(&path,
+						       osm_physp_get_port_num
+						       (p_physp))) {
+					OSM_LOG(sm->p_log, OSM_LOG_ERROR,
+						"ERR 0F08: "
+						"DR path with hop count %d couldn't be extended\n",
+						path.hop_count);
+					break;
+				}
 
 				memset(&context, 0, sizeof(context));
 				context.ni_context.node_guid =
diff --git a/opensm/opensm/osm_state_mgr.c b/opensm/opensm/osm_state_mgr.c
index adc39a0..90bef87 100644
--- a/opensm/opensm/osm_state_mgr.c
+++ b/opensm/opensm/osm_state_mgr.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2008 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
+ * Copyright (c) 2009 HNR Consulting. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -166,7 +167,13 @@ static void state_mgr_get_remote_port_info(IN osm_sm_t * sm,
 	/* generate a dr path leaving on the physp to the remote node */
 	p_dr_path = osm_physp_get_dr_path_ptr(p_physp);
 	memcpy(&rem_node_dr_path, p_dr_path, sizeof(osm_dr_path_t));
-	osm_dr_path_extend(&rem_node_dr_path, osm_physp_get_port_num(p_physp));
+	if (osm_dr_path_extend(&rem_node_dr_path, osm_physp_get_port_num(p_physp))) {
+		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 332D: "
+			"DR path with hop count %d couldn't be extended "
+			"so skipping PortInfo query\n",
+			p_dr_path->hop_count);
+		goto Exit;
+	}
 
 	memset(&mad_context, 0, sizeof(mad_context));
 
@@ -187,6 +194,7 @@ static void state_mgr_get_remote_port_info(IN osm_sm_t * sm,
 		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 332E: "
 			"Request for PortInfo failed\n");
 
+Exit:
 	OSM_LOG_EXIT(sm->p_log);
 }
 



More information about the general mailing list