[openib-general] [PATCH] librdmacm: ucma_init reads past end of device_list

Boyd R. Faulkner faulkner at opengridcomputing.com
Thu Jun 1 15:06:05 PDT 2006


The code currently in place seems to expect there to be a null element at the 
end of the dev_list to trigger the end of the loop.  ibv_get_device_list
does not provide such an entry, but the number of entries is
available.  This patch retrieves that number and loops based on it.
If ibv_get_device_list should return a list with a null element at the end,
then it is not working correctly.  This patch will work with either of the
possible intended behaviors of ibv_get_device_list.

Fix spelling of "liste".


Index: cma.c
===================================================================
--- cma.c	(revision 7568)
+++ cma.c	(working copy)
@@ -183,6 +183,7 @@
 static int ucma_init(void)
 {
 	int i;
+	int num_devices;
 	struct cma_device *cma_dev;
 	struct ibv_device_attr attr;
 	int ret;
@@ -201,14 +202,14 @@
 		goto err;
 	}
 
-	dev_list = ibv_get_device_list(NULL);
+	dev_list = ibv_get_device_list(&num_devices);
 	if (!dev_list) {
-		printf("CMA: unable to get RDMA device liste\n");
+		printf("CMA: unable to get RDMA device list\n");
 		ret = -ENODEV;
 		goto err;
 	}
 
-	for (i = 0; dev_list[i]; ++i) {
+	for (i = 0; i < num_devices; ++i) {
 		cma_dev = malloc(sizeof *cma_dev);
 		if (!cma_dev) {
 			ret = -ENOMEM;



More information about the general mailing list