[ofa-general] [infiniband-diags] [PATCH] [3/4] libibnetdisc cleanup patches round 2

Al Chu chu11 at llnl.gov
Thu Jul 9 13:21:21 PDT 2009


Check input parameters to libibnetdisc functions.

Al

-- 
Albert Chu
chu11 at llnl.gov
Computer Scientist
High Performance Systems Division
Lawrence Livermore National Laboratory
-------------- next part --------------
>From 509983720abadf313f7068b2bbe2933bafeefb84 Mon Sep 17 00:00:00 2001
From: Albert Chu <chu11 at llnl.gov>
Date: Wed, 8 Jul 2009 16:47:33 -0700
Subject: [PATCH] Check input parameters to libibnetdisc functions

Signed-off-by: Albert Chu <chu11 at llnl.gov>
Signed-off-by: Ira Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/libibnetdisc/src/chassis.c   |   15 ++++++++
 infiniband-diags/libibnetdisc/src/ibnetdisc.c |   47 ++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 1 deletions(-)

diff --git a/infiniband-diags/libibnetdisc/src/chassis.c b/infiniband-diags/libibnetdisc/src/chassis.c
index bec24bc..064d0b1 100644
--- a/infiniband-diags/libibnetdisc/src/chassis.c
+++ b/infiniband-diags/libibnetdisc/src/chassis.c
@@ -54,6 +54,11 @@ static char *ChassisSlotTypeStr[4] = { "", "Line", "Spine", "SRBD" };
 
 char *ibnd_get_chassis_type(ibnd_node_t *node)
 {
+        if (!node) {
+                IBND_DEBUG("node parameter NULL\n");
+                return (NULL);
+        }
+
 	/* Currently, only if Voltaire chassis */
 	if (mad_get_field(node->info, 0, IB_NODE_VENDORID_F) != VTR_VENDOR_ID)
 		return (NULL);
@@ -67,6 +72,11 @@ char *ibnd_get_chassis_type(ibnd_node_t *node)
 
 char *ibnd_get_chassis_slot_str(ibnd_node_t *node, char *str, size_t size)
 {
+        if (!node) {
+                IBND_DEBUG("node parameter NULL\n");
+                return (NULL);
+        }
+
 	/* Currently, only if Voltaire chassis */
 	if (mad_get_field(node->info, 0, IB_NODE_VENDORID_F) != VTR_VENDOR_ID)
 		return (NULL);
@@ -216,6 +226,11 @@ uint64_t ibnd_get_chassis_guid(ibnd_fabric_t *fabric, unsigned char chassisnum)
 	struct ibnd_fabric_int *f = CONV_FABRIC_INTERNAL(fabric);
 	ibnd_chassis_t *chassis;
 
+        if (!fabric) {
+                IBND_DEBUG("fabric parameter NULL\n");
+                return 0;
+        }
+
 	chassis = find_chassisnum(f, chassisnum);
 	if (chassis)
 		return chassis->chassisguid;
diff --git a/infiniband-diags/libibnetdisc/src/ibnetdisc.c b/infiniband-diags/libibnetdisc/src/ibnetdisc.c
index 7d9069b..88fb7df 100644
--- a/infiniband-diags/libibnetdisc/src/ibnetdisc.c
+++ b/infiniband-diags/libibnetdisc/src/ibnetdisc.c
@@ -239,6 +239,11 @@ ibnd_find_node_guid(ibnd_fabric_t *fabric, uint64_t guid)
 	int hash = HASHGUID(guid) % HTSZ;
 	struct ibnd_node_int *node;
 
+	if (!fabric) {
+		IBND_DEBUG("fabric parameter NULL\n");
+		return (NULL);
+	}
+
 	for (node = f->nodestbl[hash]; node; node = node->htnext)
 		if (node->node.guid == guid)
 			return (ibnd_node_t *)node;
@@ -275,6 +280,16 @@ ibnd_update_node(struct ibmad_port *ibmad_port, ibnd_fabric_t *fabric, ibnd_node
 	if (_check_ibmad_port(ibmad_port) < 0)
 		return (NULL);
 
+	if (!fabric) {
+		IBND_DEBUG("fabric parameter NULL\n");
+		return (NULL);
+	}
+
+	if (!node) {
+		IBND_DEBUG("node parameter NULL\n");
+		return (NULL);
+	}
+
 	if (query_node_info(ibmad_port, f, n, &(n->node.path_portid)))
 		return (NULL);
 
@@ -313,9 +328,16 @@ ibnd_find_node_dr(ibnd_fabric_t *fabric, char *dr_str)
 {
 	struct ibnd_fabric_int *f = CONV_FABRIC_INTERNAL(fabric);
 	int i = 0;
-	ibnd_node_t *rc = f->fabric.from_node;
+	ibnd_node_t *rc;
 	ib_dr_path_t path;
 
+	if (!fabric) {
+		IBND_DEBUG("fabric parameter NULL\n");
+		return (NULL);
+	}
+
+	rc = f->fabric.from_node;
+
 	if (str2drpath(&path, dr_str, 0, 0) == -1) {
 		return (NULL);
 	}
@@ -640,6 +662,9 @@ ibnd_destroy_fabric(ibnd_fabric_t *fabric)
 	struct ibnd_node_int *next = NULL;
 	ibnd_chassis_t *ch, *ch_next;
 
+	if (!fabric)
+		return;
+
 	ch = f->first_chassis;
 	while (ch) {
 		ch_next = ch->next;
@@ -684,6 +709,16 @@ ibnd_iter_nodes(ibnd_fabric_t *fabric,
 {
 	ibnd_node_t *cur = NULL;
 
+	if (!fabric) {
+		IBND_DEBUG("fabric parameter NULL\n");
+		return;
+	}
+
+	if (!func) {
+		IBND_DEBUG("func parameter NULL\n");
+		return;
+	}
+
 	for (cur = fabric->nodes; cur; cur = cur->next) {
 		func(cur, user_data);
 	}
@@ -700,6 +735,16 @@ ibnd_iter_nodes_type(ibnd_fabric_t *fabric,
 	struct ibnd_node_int *list = NULL;
 	struct ibnd_node_int *cur = NULL;
 
+	if (!fabric) {
+		IBND_DEBUG("fabric parameter NULL\n");
+		return;
+	}
+
+	if (!func) {
+		IBND_DEBUG("func parameter NULL\n");
+		return;
+	}
+
 	switch (node_type) {
 		case IB_NODE_SWITCH:
 			list = f->switches;
-- 
1.5.4.5



More information about the general mailing list