[openib-general] avoid segv in libibverbs/examples

Pete Wyckoff pw at osc.edu
Thu Aug 18 08:49:28 PDT 2005


rolandd at cisco.com wrote on Mon, 15 Aug 2005 11:46 -0700:
> Thanks.  I think we should probably print a diagnostic if no devices
> are found.  Can you resend the patch with that fixed, and also include
> a "Signed-off-by:" line?

Sure.  I just copied a complaint from a few lines lower in each
file.  There are probably nicer ways to do it.  Now a failure says:

    titan$ ibv_devices
    libibverbs: Fatal: couldn't open sysfs class 'infiniband_verbs'.
    No IB devices found

		-- Pete


Avoid segv when no IB devices are found.

Signed-off-by: Pete Wyckoff <pw at osc.edu>

Index: libibverbs/examples/asyncwatch.c
===================================================================
--- libibverbs/examples/asyncwatch.c	(revision 3132)
+++ libibverbs/examples/asyncwatch.c	(working copy)
@@ -56,6 +56,10 @@
 	struct ibv_async_event event;
 
 	dev_list = ibv_get_devices();
+	if (!dev_list) {
+		fprintf(stderr, "No IB devices found\n");
+		return 1;
+	}
 
 	dlist_start(dev_list);
 	ib_dev = dlist_next(dev_list);
Index: libibverbs/examples/rc_pingpong.c
===================================================================
--- libibverbs/examples/rc_pingpong.c	(revision 3132)
+++ libibverbs/examples/rc_pingpong.c	(working copy)
@@ -524,6 +524,10 @@
 	page_size = sysconf(_SC_PAGESIZE);
 
 	dev_list = ibv_get_devices();
+	if (!dev_list) {
+		fprintf(stderr, "No IB devices found\n");
+		return 1;
+	}
 
 	dlist_start(dev_list);
 	if (!ib_devname) {
Index: libibverbs/examples/srq_pingpong.c
===================================================================
--- libibverbs/examples/srq_pingpong.c	(revision 3132)
+++ libibverbs/examples/srq_pingpong.c	(working copy)
@@ -593,6 +593,10 @@
 	page_size = sysconf(_SC_PAGESIZE);
 
 	dev_list = ibv_get_devices();
+	if (!dev_list) {
+		fprintf(stderr, "No IB devices found\n");
+		return 1;
+	}
 
 	dlist_start(dev_list);
 	if (!ib_devname) {
Index: libibverbs/examples/uc_pingpong.c
===================================================================
--- libibverbs/examples/uc_pingpong.c	(revision 3132)
+++ libibverbs/examples/uc_pingpong.c	(working copy)
@@ -516,6 +516,10 @@
 	page_size = sysconf(_SC_PAGESIZE);
 
 	dev_list = ibv_get_devices();
+	if (!dev_list) {
+		fprintf(stderr, "No IB devices found\n");
+		return 1;
+	}
 
 	dlist_start(dev_list);
 	if (!ib_devname) {
Index: libibverbs/examples/ud_pingpong.c
===================================================================
--- libibverbs/examples/ud_pingpong.c	(revision 3132)
+++ libibverbs/examples/ud_pingpong.c	(working copy)
@@ -520,6 +520,10 @@
 	page_size = sysconf(_SC_PAGESIZE);
 
 	dev_list = ibv_get_devices();
+	if (!dev_list) {
+		fprintf(stderr, "No IB devices found\n");
+		return 1;
+	}
 
 	dlist_start(dev_list);
 	if (!ib_devname) {
Index: libibverbs/examples/device_list.c
===================================================================
--- libibverbs/examples/device_list.c	(revision 3132)
+++ libibverbs/examples/device_list.c	(working copy)
@@ -55,6 +55,10 @@
 	struct ibv_device *ib_dev;
 
 	dev_list = ibv_get_devices();
+	if (!dev_list) {
+		fprintf(stderr, "No IB devices found\n");
+		return 1;
+	}
 
 	printf("    %-16s\t   node GUID\n", "device");
 	printf("    %-16s\t----------------\n", "------");
Index: libibverbs/examples/devinfo.c
===================================================================
--- libibverbs/examples/devinfo.c	(revision 3132)
+++ libibverbs/examples/devinfo.c	(working copy)
@@ -58,6 +58,10 @@
         int i;
 
 	dev_list = ibv_get_devices();
+	if (!dev_list) {
+		fprintf(stderr, "No IB devices found\n");
+		return 1;
+	}
 
 	dlist_start(dev_list);
 	ib_dev = dlist_next(dev_list);



More information about the general mailing list