[ofa-general] [PATCH] iblinkinfo, ibqueryerrors: prevent core when switch is not found

Ira Weiny weiny2 at llnl.gov
Wed Jun 17 10:08:12 PDT 2009


From: Ira Weiny <weiny2 at llnl.gov>
Date: Thu, 14 May 2009 15:52:42 -0700
Subject: [PATCH] iblinkinfo, ibqueryerrors: prevent core when switch is not found

	If the switch is not found print nice error message instead of seg faulting

Signed-off-by: Ira Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/src/iblinkinfo.c    |   11 +++++++++--
 infiniband-diags/src/ibqueryerrors.c |   10 ++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/infiniband-diags/src/iblinkinfo.c b/infiniband-diags/src/iblinkinfo.c
index cf38ecb..367056c 100644
--- a/infiniband-diags/src/iblinkinfo.c
+++ b/infiniband-diags/src/iblinkinfo.c
@@ -395,11 +395,18 @@ main(int argc, char **argv)
 			goto close_port;
 		}
 
-	if (guid) {
+	if (guid_str) {
 		ibnd_node_t *sw = ibnd_find_node_guid(fabric, guid);
-		print_switch(sw, NULL);
+		if (sw)
+			print_switch(sw, NULL);
+		else
+			fprintf(stderr, "Failed to find switch: %s\n", guid_str);
 	} else if (dr_path) {
 		ibnd_node_t *sw = ibnd_find_node_dr(fabric, dr_path);
+		if (sw)
+			print_switch(sw, NULL);
+		else
+			fprintf(stderr, "Failed to find switch: %s\n", dr_path);
 		print_switch(sw, NULL);
 	} else {
 		ibnd_iter_nodes_type(fabric, print_switch, IB_NODE_SWITCH, NULL);
diff --git a/infiniband-diags/src/ibqueryerrors.c b/infiniband-diags/src/ibqueryerrors.c
index 525af70..999329e 100644
--- a/infiniband-diags/src/ibqueryerrors.c
+++ b/infiniband-diags/src/ibqueryerrors.c
@@ -445,10 +445,16 @@ main(int argc, char **argv)
 
 	if (switch_guid) {
 		ibnd_node_t *node = ibnd_find_node_guid(fabric, switch_guid);
-		print_node(node, NULL);
+		if (node)
+			print_node(node, NULL);
+		else
+			fprintf(stderr, "Failed to find node: %s\n", switch_guid_str);
 	} else if (dr_path) {
 		ibnd_node_t *node = ibnd_find_node_dr(fabric, dr_path);
-		print_node(node, NULL);
+		if (node)
+			print_node(node, NULL);
+		else
+			fprintf(stderr, "Failed to find node: %s\n", dr_path);
 	} else
 		ibnd_iter_nodes(fabric, print_node, NULL);
 
-- 
1.5.4.5




More information about the general mailing list