Skip to contentSkip to conversation

coverity/clang fixups

PATCH New Jarod Wilson 1 participant 24 messages Aug 18, 2016 1 message not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

cover coverity/clang fixups

I previously sent a patch to only send_lat to fix some memory leaks reported by coverity, but there were a few issues in it, and then I found that I'd overlooked similar coverity warnings for almost every other tool as well. Overall, perftest-3.0-3.1 was reporting around 55 defects in coverity. After this patchset, coverity only reports 7 defects, all of which are in the category of just warnings, and the code is fine as-is. (It warns about using weak crypto, which I don't think is worth worrying about in test apps, and about possible scalar taint when reading from /proc/cpuinfo, which isn't a random input file so little risk there, and something about a result always being 0 using the INSERTF macro for certain values, which is fine).

I've quickly regression-tested my local perftest tree after all these changes on a pair of ConnectX-4 (mlx5) hosts in our lab, and everything works the same as before the patches.

Jarod Wilson (23):
send_lat: fix assorted memory leaks on error paths
perftest_resources: print error received for debug convenience
send_bw: fix assorted memory leaks on error paths
atomic_bw: fix assorted memory leaks on error paths
atomic_lat: fix assorted memory leaks on error paths
raw_ethernet_send_lat: fix assorted memory leaks on error paths
read_bw: fix assorted memory leaks on error paths
read_lat: fix assorted memory leaks on error paths
write_bw: fix assorted memory leaks on error paths
write_lat: fix assorted memory leaks on error paths
raw_ethernet_resources: fix possible NULL math
perftest_communication: fix gid_index2 copy-pasta
perftest_communication: don't leak addrinfo
perftest_communication: fix ibv_create_ah failure check
perftest_communication: fix overflow w/size_of_cur=4
perftest: check for NULL fgets() returns
perftest_parameters: remove dead code in printf
perftest_resources: do 64-bit math setting tarr_size
perftest_resources: make sure num_of_qps is never 0
raw_ethernet_send_lat: prevent possible destroy on uninit val
perftest_communication: check for error calling setsockopt()
multicast_resources: use strncpy() to prevent overflow possibility
perftest: replace 0/1 with SUCCESS/FAILURE

 src/atomic_bw.c              |  55 ++++++++------
 src/atomic_lat.c             |  52 +++++++------
 src/multicast_resources.c    |   2 +-
 src/perftest_communication.c | 173 ++++++++++++++++++++++---------------------
 src/perftest_parameters.c    |  53 ++++++-------
 src/perftest_resources.c     | 129 +++++++++++++++++---------------
 src/raw_ethernet_resources.c |  15 ++--
 src/raw_ethernet_send_bw.c   |  26 +++----
 src/raw_ethernet_send_lat.c  |  65 +++++++++-------
 src/read_bw.c                |  76 +++++++++++--------
 src/read_lat.c               |  55 ++++++++------
 src/send_bw.c                | 118 ++++++++++++++++-------------
 src/send_lat.c               |  89 +++++++++++++---------
 src/write_bw.c               |  81 +++++++++++---------
 src/write_lat.c              |  38 ++++++----
 15 files changed, 578 insertions(+), 449 deletions(-)
CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH 1/23 send_lat: fix assorted memory leaks on error paths

In reply to a message not in the archive

Clang noticed that we might leak mcg_params.ib_devname in failure paths. There are additional leaks after fixing this initial one that it still reported, here's hoping I've got them all now...

1. perftest-3.0/src/send_lat.c:232:3: warning: Potential leak of memory pointed to by 'mcg_params.ib_devname'
# fprintf(stderr, " Couldn't get context for the device\n");
# ^
4. perftest-3.0/src/send_lat.c:203:6: note: Assuming 'ret_val' is 0
# if (ret_val) {
# ^~~~~~~
7. perftest-3.0/src/send_lat.c:203:2: note: Taking false branch
# if (ret_val) {
# ^
10. perftest-3.0/src/send_lat.c:209:5: note: Left side of '||' is false
# if(user_param.use_xrc || user_param.connection_type == DC) {
# ^
13. perftest-3.0/src/send_lat.c:209:2: note: Taking false branch
# if(user_param.use_xrc || user_param.connection_type == DC) {
# ^
16. perftest-3.0/src/send_lat.c:214:2: note: Taking false branch
# if (user_param.connection_type == RawEth) {
# ^
19. perftest-3.0/src/send_lat.c:221:6: note: Assuming 'ib_dev' is non-null
# if (!ib_dev) {
# ^~~~~~~
22. perftest-3.0/src/send_lat.c:221:2: note: Taking false branch
# if (!ib_dev) {
# ^
25. perftest-3.0/src/send_lat.c:226:2: note: Taking true branch
# if (user_param.use_mcg)
# ^
28. perftest-3.0/src/send_lat.c:227:3: note: Memory is allocated
# GET_STRING(mcg_params.ib_devname,ibv_get_device_name(ib_dev));
# ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31. perftest-3.0/src/perftest_parameters.h:217:3: note: expanded from macro 'GET_STRING'
# { ALLOCATE(orig,char,(strlen(temp) + 1)); strcpy(orig,temp); }
# ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34. perftest-3.0/src/perftest_parameters.h:212:20: note: expanded from macro 'ALLOCATE'
# { if((var = (type*)malloc(sizeof(type)*(size))) == NULL) \
# ^~~~~~~~~~~~~~~~~~~~~~~~~~~
37. perftest-3.0/src/send_lat.c:227:3: note: Taking false branch
38. perftest-3.0/src/perftest_parameters.h:217:3: note: expanded from macro 'GET_STRING'
# { ALLOCATE(orig,char,(strlen(temp) + 1)); strcpy(orig,temp); }
# ^
41. perftest-3.0/src/perftest_parameters.h:212:3: note: expanded from macro 'ALLOCATE'
# { if((var = (type*)malloc(sizeof(type)*(size))) == NULL) \
# ^
44. perftest-3.0/src/send_lat.c:231:2: note: Taking true branch
# if (!ctx.context) {
# ^
47. perftest-3.0/src/send_lat.c:232:3: note: Potential leak of memory pointed to by 'mcg_params.ib_devname'
# fprintf(stderr, " Couldn't get context for the device\n");
# ^

 #   230|   	ctx.context = ibv_open_device(ib_dev);
 #   231|   	if (!ctx.context) {
 #   232|-> 		fprintf(stderr, " Couldn't get context for the device\n");
 #   233|   		return 1;
 #   234|   	}

v2: fix up failure labels and segfault on qp alloc fail

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/send_lat.c | 71 +++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 28 deletions(-)
src/send_lat.c +43 -28
index 282cf11..cc424c4 100755
@@ -205,9 +205,11 @@ int main(int argc, char *argv[])
 	if (ret_val) {
 		if (ret_val != VERSION_EXIT && ret_val != HELP_EXIT)
 			fprintf(stderr," Parser function exited with Error\n");
-		return 1;
+		return FAILURE;
 	}
 
+	ret_val = FAILURE;
+
 	if(user_param.use_xrc || user_param.connection_type == DC) {
 		user_param.num_of_qps *= 2;
 	}
@@ -215,14 +217,14 @@ int main(int argc, char *argv[])
 	/* Checking that the user did not run with RawEth. for this we have raw_etherent_bw test. */
 	if (user_param.connection_type == RawEth) {
 		fprintf(stderr," This test cannot run Raw Ethernet QPs (you have chosen RawEth as connection type\n");
-		return FAILURE;
+		return ret_val;
 	}
 
 	/* Finding the IB device selected (or defalut if no selected). */
 	ib_dev = ctx_find_dev(user_param.ib_devname);
 	if (!ib_dev) {
 		fprintf(stderr," Unable to find the Infiniband/RoCE device\n");
-		return 1;
+		return ret_val;
 	}
 
 	if (user_param.use_mcg)
@@ -232,19 +234,19 @@ int main(int argc, char *argv[])
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		goto free_ib_devname;
 	}
 
 	/* See if MTU and link type are valid and supported. */
 	if (check_link(ctx.context,&user_param)) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return FAILURE;
+		goto free_ib_devname;
 	}
 
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm,&user_param)) {
 		fprintf(stderr," Unable to create RDMA_CM resources\n");
-		return 1;
+		goto free_ib_devname;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -256,7 +258,7 @@ int main(int argc, char *argv[])
 	/* Initialize the connection and print the local data. */
 	if (establish_connection(&user_comm)) {
 		fprintf(stderr," Unable to init the socket connection\n");
-		return FAILURE;
+		goto free_ib_devname;
 	}
 
 	exchange_versions(&user_comm, &user_param);
@@ -266,7 +268,7 @@ int main(int argc, char *argv[])
 	/* See if MTU and link type are valid and supported. */
 	if (check_mtu(ctx.context,&user_param, &user_comm)) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return FAILURE;
+		goto free_ib_devname;
 	}
 
 	ALLOCATE(my_dest , struct pingpong_dest , user_param.num_of_qps);
@@ -283,17 +285,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx,&user_param)) {
 				fprintf(stderr," Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -302,14 +304,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources (data buffer, PD, MR, CQ and events channel) */
 		if (ctx_init(&ctx,&user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (send_set_up_connection(&ctx,&user_param,my_dest,&mcg_params,&user_comm)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -324,7 +326,7 @@ int main(int argc, char *argv[])
 		/* shaking hands and gather the other side info. */
 		if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		ctx_print_pingpong_data(&rem_dest[i],&user_comm);
@@ -334,7 +336,7 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr,"\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr," Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -348,7 +350,7 @@ int main(int argc, char *argv[])
 			/* Request for Mcast group create registery in SM. */
 			if (join_multicast_group(SUBN_ADM_METHOD_SET,&mcg_params)) {
 				fprintf(stderr," Failed to Join Mcast request\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 
@@ -369,26 +371,26 @@ int main(int argc, char *argv[])
 		/* Prepare IB resources for rtr/rts. */
 		if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	/* shaking hands and gather the other side info. */
 	if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (user_param.use_event) {
 
 		if (ibv_req_notify_cq(ctx.send_cq, 0)) {
 			fprintf(stderr, "Couldn't request RCQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		if (ibv_req_notify_cq(ctx.recv_cq, 0)) {
 			fprintf(stderr, "Couldn't request RCQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 	if (user_param.output == FULL_VERBOSITY) {
@@ -411,7 +413,7 @@ int main(int argc, char *argv[])
 			/* Post receive recv_wqes fo current message size */
 			if (ctx_set_recv_wqes(&ctx,&user_param)) {
 				fprintf(stderr," Failed to post receive recv_wqes\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
 			/* Sync between the client and server so the client won't send packets
@@ -420,11 +422,13 @@ int main(int argc, char *argv[])
 
 			if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 				fprintf(stderr,"Failed to exchange data between server and clients\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
-			if(run_iter_lat_send(&ctx, &user_param))
-				return 17;
+			if(run_iter_lat_send(&ctx, &user_param)) {
+				ret_val = 17;
+				goto destroy_ctx;
+			}
 
 			user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param);
 		}
@@ -434,7 +438,7 @@ int main(int argc, char *argv[])
 		/* Post recevie recv_wqes fo current message size */
 		if (ctx_set_recv_wqes(&ctx,&user_param)) {
 			fprintf(stderr," Failed to post receive recv_wqes\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		/* Sync between the client and server so the client won't send packets
@@ -443,11 +447,13 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
-		if(run_iter_lat_send(&ctx, &user_param))
-			return 17;
+		if(run_iter_lat_send(&ctx, &user_param)) {
+			ret_val = 17;
+			goto destroy_ctx;
+		}
 
 		user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param);
 	}
@@ -462,4 +468,13 @@ int main(int argc, char *argv[])
 	}
 
 	return send_destroy_ctx(&ctx,&user_param,&mcg_params);
+
+destroy_ctx:
+	destroy_ctx(&ctx,&user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+free_ib_devname:
+	free(mcg_params.ib_devname);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH 2/23 perftest_resources: print error received for debug convenience

In reply to a message not in the archive
CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_resources.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
src/perftest_resources.c +7 -7
index f23dabb..4dc0705 100755
@@ -1855,7 +1855,7 @@ int ctx_modify_dc_qp_to_init(struct ibv_qp *qp,struct perftest_parameters *user_
 	#endif
 
 	if (err) {
-		fprintf(stderr, "Failed to modify QP to INIT\n");
+		fprintf(stderr, "Failed to modify QP to INIT (%s)\n", strerror(err));
 		return 1;
 	}
 	return 0;
@@ -1951,7 +1951,7 @@ int ctx_modify_qp_to_init(struct ibv_qp *qp,struct perftest_parameters *user_par
 		ret = ibv_modify_qp(qp,&attr,flags);
 
 	if (ret) {
-		fprintf(stderr, "Failed to modify QP to INIT, ret=%d\n",ret);
+		fprintf(stderr, "Failed to modify QP to INIT, (%s)\n",strerror(ret));
 		return 1;
 	}
 	return 0;
@@ -2261,7 +2261,7 @@ int ctx_connect(struct pingpong_context *ctx,
 
 			err = ibv_query_qp(ctx->qp[i], &qp_attr, IBV_QP_AV, &init_attr);
 			if (err)
-				fprintf(stderr, "ibv_query_qp failed to get ah_attr\n");
+				fprintf(stderr, "ibv_query_qp failed to get ah_attr (%s)\n", strerror(err));
 			else
 				qp_static_rate = (int)(qp_attr.ah_attr.static_rate);
 
@@ -2816,7 +2816,7 @@ int perform_warm_up(struct pingpong_context *ctx,struct perftest_parameters *use
 			#endif
 
 			if (err) {
-				fprintf(stderr,"Couldn't post send during warm up: qp %d scnt=%d \n",index,warmindex);
+				fprintf(stderr,"Couldn't post send during warm up: qp %d scnt=%d, err=%s\n",index,warmindex,strerror(err));
 				return_value = 1;
 				goto cleaning;
 			}
@@ -4016,7 +4016,7 @@ int run_iter_lat_write(struct pingpong_context *ctx,struct perftest_parameters *
 			err = ibv_post_send(ctx->qp[0],&ctx->wr[0],&bad_wr);
 			#endif
 			if (err) {
-				fprintf(stderr,"Couldn't post send: scnt=%lu\n",scnt);
+				fprintf(stderr,"%s: Couldn't post send: scnt=%lu, err=%s\n",__func__,scnt,strerror(err));
 				return 1;
 			}
 		}
@@ -4110,7 +4110,7 @@ int run_iter_lat(struct pingpong_context *ctx,struct perftest_parameters *user_p
 		err = ibv_post_send(ctx->qp[0],&ctx->wr[0],&bad_wr);
 		#endif
 		if (err) {
-			fprintf(stderr,"Couldn't post send: scnt=%lu\n",scnt);
+			fprintf(stderr,"%s: Couldn't post send: scnt=%lu, err=%s\n",__func__,scnt,strerror(err));
 			return 1;
 		}
 
@@ -4310,7 +4310,7 @@ int run_iter_lat_send(struct pingpong_context *ctx,struct perftest_parameters *u
 			err = ibv_post_send(ctx->qp[0],&ctx->wr[0],&bad_wr);
 			#endif
 			if (err) {
-				fprintf(stderr,"Couldn't post send: scnt=%lu \n",scnt);
+				fprintf(stderr,"%s: Couldn't post send: scnt=%lu, err=%s \n",__func__,scnt,strerror(err));
 				return 1;
 			}
 
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH 3/23 send_bw: fix assorted memory leaks on error paths

In reply to a message not in the archive

Clang reported a bunch of memory leaks. This plugs 'em all.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/send_bw.c | 100 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 59 insertions(+), 41 deletions(-)
src/send_bw.c +59 -41
index b018aa1..45cbb67 100755
@@ -162,6 +162,7 @@ int main(int argc, char *argv[])
 	struct bw_report_data		my_bw_rep, rem_bw_rep;
 	int                      	ret_parser,i = 0;
 	int                      	size_max_pow = 24;
+	int				ret_val = FAILURE;
 
 	/* init default values to user's parameters */
 	memset(&ctx, 0,sizeof(struct pingpong_context));
@@ -178,7 +179,7 @@ int main(int argc, char *argv[])
 	if (ret_parser) {
 		if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT)
 			fprintf(stderr," Parser function exited with Error\n");
-		return 1;
+		return ret_val;
 	}
 	if((user_param.connection_type == DC || user_param.use_xrc) && user_param.duplex) {
 		user_param.num_of_qps *= 2;
@@ -187,14 +188,14 @@ int main(int argc, char *argv[])
 	if (user_param.connection_type == RawEth) {
 		fprintf(stderr," This test cannot run Raw Ethernet QPs (you have chosen RawEth as connection type\n");
 		fprintf(stderr," For this we have raw_ethernet_bw test in this package.\n");
-		return FAILURE;
+		return ret_val;
 	}
 
 	/* Finding the IB device selected (or defalut if no selected). */
 	ib_dev = ctx_find_dev(user_param.ib_devname);
 	if (!ib_dev) {
 		fprintf(stderr," Unable to find the Infiniband/RoCE device\n");
-		return 1;
+		return ret_val;
 	}
 
 	if (user_param.use_mcg)
@@ -204,20 +205,20 @@ int main(int argc, char *argv[])
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		goto free_ib_devname;
 	}
 
 
 	/* See if MTU and link type are valid and supported. */
 	if (check_link(ctx.context,&user_param)) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return FAILURE;
+		goto free_ib_devname;
 	}
 
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm,&user_param)) {
 		fprintf(stderr," Unable to create RDMA_CM resources\n");
-		return 1;
+		goto free_ib_devname;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -229,7 +230,7 @@ int main(int argc, char *argv[])
 	/* Initialize the connection and print the local data. */
 	if (establish_connection(&user_comm)) {
 		fprintf(stderr," Unable to init the socket connection\n");
-		return FAILURE;
+		goto free_ib_devname;
 	}
 
 	exchange_versions(&user_comm, &user_param);
@@ -239,7 +240,7 @@ int main(int argc, char *argv[])
 	/* See if MTU and link type are valid and supported. */
 	if (check_mtu(ctx.context,&user_param, &user_comm)) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return FAILURE;
+		goto free_ib_devname;
 	}
 
 	ALLOCATE(my_dest , struct pingpong_dest , user_param.num_of_qps);
@@ -259,17 +260,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx,&user_param)) {
 				fprintf(stderr," Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -278,14 +279,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources (data buffer, PD, MR, CQ and events channel) */
 		if (ctx_init(&ctx,&user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (send_set_up_connection(&ctx,&user_param,my_dest,&mcg_params,&user_comm)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -303,7 +304,7 @@ int main(int argc, char *argv[])
 		/* shaking hands and gather the other side info. */
 		if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		ctx_print_pingpong_data(&rem_dest[i],&user_comm);
@@ -313,7 +314,7 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr,"\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr," Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -330,7 +331,7 @@ int main(int argc, char *argv[])
 		memcpy(mcg_params.mgid.raw, rem_dest[0].gid.raw, 16);
 		if (set_mcast_group(&ctx,&user_param,&mcg_params)) {
 			fprintf(stderr," Unable to Join Sender to Mcast gid\n");
-			return 1;
+			goto destroy_ctx;
 		}
 		/*
 		 * The next stall in code (50 ms sleep) is a work around for fixing the
@@ -349,26 +350,26 @@ int main(int argc, char *argv[])
 		/* Prepare IB resources for rtr/rts. */
 		if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	/* shaking hands and gather the other side info. */
 	if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (user_param.use_event) {
 
 		if (ibv_req_notify_cq(ctx.send_cq, 0)) {
 			fprintf(stderr, " Couldn't request CQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		if (ibv_req_notify_cq(ctx.recv_cq, 0)) {
 			fprintf(stderr, " Couldn't request CQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -399,13 +400,13 @@ int main(int argc, char *argv[])
 			if (user_param.machine == SERVER || user_param.duplex) {
 				if (ctx_set_recv_wqes(&ctx,&user_param)) {
 					fprintf(stderr," Failed to post receive recv_wqes\n");
-					return 1;
+					goto destroy_ctx;
 				}
 			}
 
 			if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 				fprintf(stderr,"Failed to exchange data between server and clients\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
 			if (ctx.send_rcredit) {
@@ -415,19 +416,23 @@ int main(int argc, char *argv[])
 			}
 
 			if (user_param.duplex) {
-				if(run_iter_bi(&ctx,&user_param))
-					return 17;
+				if(run_iter_bi(&ctx,&user_param)) {
+					ret_val = 17;
+					goto destroy_ctx;
+				}
 
 			} else if (user_param.machine == CLIENT) {
 
 				if(run_iter_bw(&ctx,&user_param)) {
-					return 17;
+					ret_val = 17;
+					goto destroy_ctx;
 				}
 
 			} else	{
 
 				if(run_iter_bw_server(&ctx,&user_param)) {
-					return 17;
+					ret_val = 17;
+					goto destroy_ctx;
 				}
 			}
 
@@ -439,7 +444,7 @@ int main(int argc, char *argv[])
 			}
 			if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 				fprintf(stderr,"Failed to exchange data between server and clients\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
 			/* Check if last iteration ended well in UC/UD */
@@ -456,29 +461,33 @@ int main(int argc, char *argv[])
 		if (user_param.machine == SERVER || user_param.duplex) {
 			if (ctx_set_recv_wqes(&ctx,&user_param)) {
 				fprintf(stderr," Failed to post receive recv_wqes\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 
 		if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		if (user_param.duplex) {
 
-			if(run_iter_bi(&ctx,&user_param))
-				return 17;
+			if(run_iter_bi(&ctx,&user_param)) {
+				ret_val = 17;
+				goto destroy_ctx;
+			}
 
 		} else if (user_param.machine == CLIENT) {
 
 			if(run_iter_bw(&ctx,&user_param)) {
-				return 17;
+				ret_val = 17;
+				goto destroy_ctx;
 			}
 
 		} else if(run_iter_bw_server(&ctx,&user_param)) {
 
-			return 17;
+			ret_val = 17;
+			goto destroy_ctx;
 		}
 
 		print_report_bw(&user_param,&my_bw_rep);
@@ -512,27 +521,27 @@ int main(int argc, char *argv[])
 
 			if (ctx_set_recv_wqes(&ctx,&user_param)) {
 				fprintf(stderr," Failed to post receive recv_wqes\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 
 		if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		if (user_param.machine == CLIENT) {
 
 			if(run_iter_bw_infinitely(&ctx,&user_param)) {
 				fprintf(stderr," Error occured while running infinitely! aborting ...\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
 		} else if (user_param.machine == SERVER) {
 
 			if(run_iter_bw_infinitely_server(&ctx,&user_param)) {
 				fprintf(stderr," Error occured while running infinitely on server! aborting ...\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 	}
@@ -552,25 +561,34 @@ int main(int argc, char *argv[])
 	/* Destory all test resources, including Mcast if exists */
 	if (send_destroy_ctx(&ctx,&user_param,&mcg_params)) {
 		fprintf(stderr,"Couldn't Destory all SEND resources\n");
-		return FAILURE;
+		goto destroy_ctx;
 	}
 	if (user_param.work_rdma_cm == ON) {
 		user_comm.rdma_params->work_rdma_cm = ON;
 		if (destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params)) {
 			fprintf(stderr,"Failed to destroy resources\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	if (!user_param.is_bw_limit_passed && (user_param.is_limit_bw == ON ) ) {
 		fprintf(stderr,"Error: BW result is below bw limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (!user_param.is_msgrate_limit_passed && (user_param.is_limit_bw == ON )) {
 		fprintf(stderr,"Error: Msg rate  is below msg_rate limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	return 0;
+
+destroy_ctx:
+	destroy_ctx(&ctx,&user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+free_ib_devname:
+	free(mcg_params.ib_devname);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

PATCH 4/23 atomic_bw: fix assorted memory leaks on error paths

In reply to a message not in the archive

These were all reported by clang. Also replaced all instances of "return 1" with "return FAILURE" for consistency.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/atomic_bw.c | 55 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 31 insertions(+), 24 deletions(-)
src/atomic_bw.c +31 -24
index 479cb1d..3de5f4c 100755
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
 	if (ret_parser) {
 		if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT)
 			fprintf(stderr, " Parser function exited with Error\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.use_xrc && user_param.duplex) {
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		return FAILURE;
 	}
 
 	#ifdef HAVE_MASKED_ATOMICS
@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
 
 	if (user_param.masked_atomics && (user_param.work_rdma_cm || user_param.use_rdma_cm)) {
 		fprintf(stderr, "atomic test is not supported with -R/-z flag (rdma_cm) with this device.\n");
-		return 1;
+		return FAILURE;
 	}
 	#endif
 
@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm, &user_param)) {
 		fprintf(stderr, " Unable to create RDMA_CM resources\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -147,17 +147,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx, &user_param)) {
 				fprintf(stderr, "Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx, &user_param)) {
 				fprintf(stderr, " Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx, &user_param)) {
 				fprintf(stderr, "Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -166,14 +166,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources. */
 		if (ctx_init(&ctx, &user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (set_up_connection(&ctx, &user_param, my_dest)) {
 		fprintf(stderr, " Unable to set up socket connection\n");
-		return FAILURE;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -189,7 +189,7 @@ int main(int argc, char *argv[])
 		/* shaking hands and gather the other side info. */
 		if (ctx_hand_shake(&user_comm, &my_dest[i], &rem_dest[i])) {
 			fprintf(stderr, "Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 		ctx_print_pingpong_data(&rem_dest[i], &user_comm);
 	}
@@ -198,21 +198,21 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr, "\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr, " Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	if (user_param.work_rdma_cm == OFF) {
 		if (ctx_connect(&ctx, rem_dest, &user_param, my_dest)) {
 			fprintf(stderr, " Unable to Connect the HCA's through the link\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	/* An additional handshake is required after moving qp to RTR. */
 	if (ctx_hand_shake(&user_comm, &my_dest[0], &rem_dest[0])) {
 		fprintf(stderr, "Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* For half duplex tests, server just waits for client to exit */
@@ -225,7 +225,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm, &my_dest[0], &rem_dest[0])) {
 			fprintf(stderr, " Failed to exchange data between server and clients\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 
 		xchg_bw_reports(&user_comm, &my_bw_rep, &rem_bw_rep, atof(user_param.rem_version));
@@ -237,7 +237,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_close_connection(&user_comm, &my_dest[0], &rem_dest[0])) {
 			fprintf(stderr, "Failed to close connection between server and client\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		return destroy_ctx(&ctx, &user_param);
@@ -246,7 +246,7 @@ int main(int argc, char *argv[])
 	if (user_param.use_event) {
 		if (ibv_req_notify_cq(ctx.send_cq, 0)) {
 			fprintf(stderr, "Couldn't request CQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 	if (user_param.output == FULL_VERBOSITY) {
@@ -261,19 +261,19 @@ int main(int argc, char *argv[])
 
 		if (perform_warm_up(&ctx, &user_param)) {
 			fprintf(stderr, "Problems with warm up\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		if (user_param.duplex) {
 			if (ctx_hand_shake(&user_comm, &my_dest[0], &rem_dest[0])) {
 				fprintf(stderr, "Failed to sync between server and client between different msg sizes\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 
 		if (run_iter_bw(&ctx, &user_param)) {
 			fprintf(stderr, " Error occured in run_iter function\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		print_report_bw(&user_param, &my_bw_rep);
@@ -302,7 +302,7 @@ int main(int argc, char *argv[])
 
 		if (run_iter_bw_infinitely(&ctx, &user_param)) {
 			fprintf(stderr, " Error occured while running infinitely! aborting ...\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -314,7 +314,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm, &my_dest[0], &rem_dest[0])) {
 			fprintf(stderr, " Failed to exchange data between server and clients\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 
 		xchg_bw_reports(&user_comm, &my_bw_rep, &rem_bw_rep, atof(user_param.rem_version));
@@ -322,18 +322,25 @@ int main(int argc, char *argv[])
 
 	if (ctx_close_connection(&user_comm, &my_dest[0], &rem_dest[0])) {
 		fprintf(stderr, "Failed to close connection between server and client\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (!user_param.is_bw_limit_passed && (user_param.is_limit_bw == ON)) {
 		fprintf(stderr, "Error: BW result is below bw limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (!user_param.is_msgrate_limit_passed && (user_param.is_limit_bw == ON)) {
 		fprintf(stderr, "Error: Msg rate  is below msg_rate limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	return destroy_ctx(&ctx, &user_param);
+
+destroy_ctx:
+	destroy_ctx(&ctx,&user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+	return FAILURE;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

PATCH 5/23 atomic_lat: fix assorted memory leaks on error paths

In reply to a message not in the archive

These were all reported by clang.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/atomic_lat.c | 52 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 21 deletions(-)
src/atomic_lat.c +31 -21
index fd61a14..213efe5 100755
@@ -55,6 +55,7 @@
 int main(int argc, char *argv[])
 {
 	int				ret_parser, i;
+	int				ret_val = FAILURE;
 	struct report_options		report;
 	struct pingpong_context		ctx;
 	struct pingpong_dest		*my_dest  = NULL;
@@ -77,7 +78,7 @@ int main(int argc, char *argv[])
 	if (ret_parser) {
 		if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT)
 			fprintf(stderr," Parser function exited with Error\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if(user_param.use_xrc)
@@ -94,7 +95,7 @@ int main(int argc, char *argv[])
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		return FAILURE;
 	}
 
 	#ifdef HAVE_MASKED_ATOMICS
@@ -105,7 +106,7 @@ int main(int argc, char *argv[])
 
 	if (user_param.masked_atomics && (user_param.work_rdma_cm || user_param.use_rdma_cm)) {
 		fprintf(stderr, "atomic test is not supported with -R/-z flag (rdma_cm) with this device.\n");
-		return 1;
+		return FAILURE;
 	}
 
 	#endif
@@ -119,7 +120,7 @@ int main(int argc, char *argv[])
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm,&user_param)) {
 		fprintf(stderr," Unable to create RDMA_CM resources\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -158,17 +159,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx,&user_param)) {
 				fprintf(stderr," Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -177,14 +178,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources (data buffer, PD, MR, CQ and events channel) */
 		if (ctx_init(&ctx,&user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (set_up_connection(&ctx,&user_param,my_dest)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -196,7 +197,7 @@ int main(int argc, char *argv[])
 	/* shaking hands and gather the other side info. */
 	if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	user_comm.rdma_params->side = REMOTE;
@@ -205,7 +206,7 @@ int main(int argc, char *argv[])
 		/* shaking hands and gather the other side info. */
 		if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		ctx_print_pingpong_data(&rem_dest[i],&user_comm);
@@ -215,39 +216,39 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr,"\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr," Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	if (user_param.work_rdma_cm == OFF) {
 		if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	/* An additional handshake is required after moving qp to RTR. */
 	if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* Only Client post read request. */
 	if (user_param.machine == SERVER) {
 		if (ctx_close_connection(&user_comm,my_dest,rem_dest)) {
 			fprintf(stderr,"Failed to close connection between server and client\n");
-			return 1;
+			goto destroy_ctx;
 		}
 		if (user_param.output == FULL_VERBOSITY) {
 			printf(RESULT_LINE);
 		}
-		return 0;
+		goto out_success;
 	}
 
 	if (user_param.use_event) {
 		if (ibv_req_notify_cq(ctx.send_cq, 0)) {
 			fprintf(stderr, "Couldn't request CQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -258,19 +259,28 @@ int main(int argc, char *argv[])
 		printf("%s",(user_param.test_type == ITERATIONS) ? RESULT_FMT_LAT : RESULT_FMT_LAT_DUR);
 		printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT));
 	}
-	if(run_iter_lat(&ctx,&user_param))
-		return 17;
+	if(run_iter_lat(&ctx,&user_param)) {
+		ret_val = 17;
+		goto destroy_ctx;
+	}
 
 	user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param);
 
 	if (ctx_close_connection(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to close connection between server and client\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (user_param.output == FULL_VERBOSITY) {
 		printf(RESULT_LINE);
 	}
 
-	return 0;
+out_success:
+	ret_val = 0;
+destroy_ctx:
+	destroy_ctx(&ctx,&user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

PATCH 6/23 raw_ethernet_send_lat: fix assorted memory leaks on error paths

In reply to a message not in the archive

Fixing issues reported by clang.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/raw_ethernet_send_lat.c | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)
src/raw_ethernet_send_lat.c +26 -17
index 4663714..6d0bbf9 100755
@@ -64,6 +64,7 @@ int main(int argc, char *argv[])
 	struct pingpong_context		ctx;
 	struct raw_ethernet_info	my_dest_info,rem_dest_info;
 	int				ret_parser;
+	int				ret_val = FAILURE;
 	struct perftest_parameters	user_param;
 	#ifdef HAVE_RAW_ETH_EXP
 	struct ibv_exp_flow		**flow_create_result;
@@ -101,7 +102,7 @@ int main(int argc, char *argv[])
 		if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT)
 			fprintf(stderr," Parser function exited with Error\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		return FAILURE;
 	}
 	#ifdef HAVE_RAW_ETH_EXP
 	ALLOCATE(flow_create_result, struct ibv_exp_flow*, user_param.flows);
@@ -122,12 +123,12 @@ int main(int argc, char *argv[])
 	if (!ib_dev) {
 		fprintf(stderr," Unable to find the Infiniband/RoCE device\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		goto free_flows;
 	}
 	GET_STRING(user_param.ib_devname, ibv_get_device_name(ib_dev));
 
 	if (check_flow_steering_support(user_param.ib_devname)) {
-		return 1;
+		goto free_flows;
 	}
 
 	/* Getting the relevant context from the device */
@@ -135,14 +136,14 @@ int main(int argc, char *argv[])
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		goto free_flows;
 	}
 
 	/* See if MTU and link type are valid and supported. */
 	if (check_link_and_mtu(ctx.context, &user_param)) {
 		fprintf(stderr, " Couldn't get context for the device\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return FAILURE;
+		goto free_flows;
 	}
 
 	/* Allocating arrays needed for the test. */
@@ -153,7 +154,7 @@ int main(int argc, char *argv[])
 	 */
 	if (send_set_up_connection(flow_rules, &ctx, &user_param, &my_dest_info, &rem_dest_info)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return 1;
+		goto free_flows;
 	}
 
 	/* Print basic test information. */
@@ -167,7 +168,7 @@ int main(int argc, char *argv[])
 
 		if (create_rdma_resources(&ctx, &user_param)) {
 			fprintf(stderr," Unable to create the rdma_resources\n");
-			return FAILURE;
+			goto free_flows;
 		}
 
 		if (user_param.machine == CLIENT) {
@@ -175,13 +176,13 @@ int main(int argc, char *argv[])
 			/* Connects the client to a QP on the other machine with rdma_cm */
 			if (rdma_client_connect(&ctx, &user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_flows;
 			}
 
 		} else if (rdma_server_connect(&ctx, &user_param)) {
 			/* Assigning a server to listen on rdma_cm port and connect to it. */
 			fprintf(stderr,"Unable to perform rdma_server function\n");
-			return FAILURE;
+			goto free_flows;
 		}
 
 	} else {
@@ -189,7 +190,7 @@ int main(int argc, char *argv[])
 		/* initalize IB resources (data buffer, PD, MR, CQ and events channel) */
 		if (ctx_init(&ctx, &user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_flows;
 		}
 	}
 
@@ -205,7 +206,7 @@ int main(int argc, char *argv[])
 		if (!flow_create_result[i]){
 			perror("error");
 			fprintf(stderr, "Couldn't attach QP\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 	}
 
@@ -239,7 +240,7 @@ int main(int argc, char *argv[])
 		if (ctx_connect(&ctx, NULL, &user_param, NULL)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
 			DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -247,12 +248,12 @@ int main(int argc, char *argv[])
 
 	if (ctx_set_recv_wqes(&ctx,&user_param)) {
 		fprintf(stderr," Failed to post receive recv_wqes\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* latency test function for SEND verb latency test. */
 	if (run_iter_lat_send(&ctx, &user_param)) {
-		return 17;
+		goto eexists;
 	}
 
 	/* print report (like print_report_bw) in the correct format
@@ -267,7 +268,7 @@ int main(int argc, char *argv[])
 		if (ibv_exp_destroy_flow(flow_promisc)) {
 			perror("error");
 			fprintf(stderr, "Couldn't Destory promisc flow\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 	}
 	#endif
@@ -281,7 +282,7 @@ int main(int argc, char *argv[])
 		#endif
 			perror("error");
 			fprintf(stderr, "Couldn't Destory flow\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 
 		free(flow_rules[i]);
@@ -291,7 +292,7 @@ int main(int argc, char *argv[])
 	if (destroy_ctx(&ctx, &user_param)) {
 		fprintf(stderr,"Failed to destroy_ctx\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY)
@@ -300,4 +301,12 @@ int main(int argc, char *argv[])
 	DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
 	return 0;
 
+eexists:
+	ret_val = 17;
+destroy_ctx:
+	destroy_ctx(&ctx, &user_param);
+free_flows:
+	free(flow_create_result);
+	free(flow_rules);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

PATCH 7/23 read_bw: fix assorted memory leaks on error paths

In reply to a message not in the archive

Reported by clang/coverity.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/read_bw.c | 76 ++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 47 insertions(+), 29 deletions(-)
src/read_bw.c +47 -29
index 47afcdb..17f75dc 100755
@@ -48,6 +48,7 @@
 int main(int argc, char *argv[])
 {
 	int                        ret_parser,i = 0;
+	int			   ret_val = FAILURE;
 	struct ibv_device	   *ib_dev = NULL;
 	struct pingpong_context    ctx;
 	struct pingpong_dest       *my_dest = NULL;
@@ -69,7 +70,7 @@ int main(int argc, char *argv[])
 	if (ret_parser) {
 		if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT)
 			fprintf(stderr," Parser function exited with Error\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if((user_param.connection_type == DC || user_param.use_xrc) && user_param.duplex) {
@@ -84,7 +85,7 @@ int main(int argc, char *argv[])
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		return FAILURE;
 	}
 
 	/* See if MTU and link type are valid and supported. */
@@ -96,7 +97,7 @@ int main(int argc, char *argv[])
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm,&user_param)) {
 		fprintf(stderr," Unable to create RDMA_CM resources\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -135,17 +136,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx,&user_param)) {
 				fprintf(stderr," Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -153,14 +154,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources. */
 		if (ctx_init(&ctx,&user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (set_up_connection(&ctx,&user_param,my_dest)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return FAILURE;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -177,7 +178,7 @@ int main(int argc, char *argv[])
 		/* shaking hands and gather the other side info. */
 		if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 		ctx_print_pingpong_data(&rem_dest[i],&user_comm);
 	}
@@ -186,7 +187,7 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr,"\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr," Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -194,14 +195,14 @@ int main(int argc, char *argv[])
 
 		if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	/* An additional handshake is required after moving qp to RTR. */
 	if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (user_param.output == FULL_VERBOSITY) {
@@ -221,7 +222,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr," Failed to exchange data between server and clients\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 
 		xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version));
@@ -229,7 +230,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr,"Failed to close connection between server and client\n");
-			return 1;
+			goto destroy_ctx;
 		}
 		if (user_param.output == FULL_VERBOSITY) {
 			if (user_param.report_per_port)
@@ -241,12 +242,16 @@ int main(int argc, char *argv[])
 		if (user_param.work_rdma_cm == ON) {
 			if (destroy_ctx(&ctx,&user_param)) {
 				fprintf(stderr, "Failed to destroy resources\n");
-				return 1;
+				goto free_dests;
 			}
 			user_comm.rdma_params->work_rdma_cm = ON;
+			free(my_dest);
+			free(rem_dest);
 			return destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params);
 		}
 
+		free(my_dest);
+		free(rem_dest);
 		return destroy_ctx(&ctx,&user_param);
 
 	}
@@ -254,7 +259,7 @@ int main(int argc, char *argv[])
 	if (user_param.use_event) {
 		if (ibv_req_notify_cq(ctx.send_cq, 0)) {
 			fprintf(stderr, "Couldn't request CQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -267,23 +272,23 @@ int main(int argc, char *argv[])
 
 			if(perform_warm_up(&ctx,&user_param)) {
 				fprintf(stderr,"Problems with warm up\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
 			if(user_param.duplex) {
 				if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 					fprintf(stderr,"Failed to sync between server and client between different msg sizes\n");
-					return 1;
+					goto destroy_ctx;
 				}
 			}
 
 			if(run_iter_bw(&ctx,&user_param))
-				return 17;
+				goto eexists;
 
 			if (user_param.duplex && (atof(user_param.version) >= 4.6)) {
 				if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 					fprintf(stderr,"Failed to sync between server and client between different msg sizes\n");
-					return 1;
+					goto destroy_ctx;
 				}
 			}
 
@@ -301,19 +306,19 @@ int main(int argc, char *argv[])
 
 		if(perform_warm_up(&ctx,&user_param)) {
 			fprintf(stderr,"Problems with warm up\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		if(user_param.duplex) {
 			if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 				fprintf(stderr,"Failed to sync between server and client between different msg sizes\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 
 		if(run_iter_bw(&ctx,&user_param)) {
 			fprintf(stderr," Failed to complete run_iter_bw function successfully\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		print_report_bw(&user_param,&my_bw_rep);
@@ -344,7 +349,7 @@ int main(int argc, char *argv[])
 
 		if(run_iter_bw_infinitely(&ctx,&user_param)) {
 			fprintf(stderr," Error occured while running! aborting ...\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -360,7 +365,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr," Failed to exchange data between server and clients\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 
 		xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version));
@@ -368,27 +373,40 @@ int main(int argc, char *argv[])
 
 	if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) {
 		fprintf(stderr,"Failed to close connection between server and client\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (!user_param.is_bw_limit_passed && (user_param.is_limit_bw == ON ) ) {
 		fprintf(stderr,"Error: BW result is below bw limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (!user_param.is_msgrate_limit_passed && (user_param.is_limit_bw == ON )) {
 		fprintf(stderr,"Error: Msg rate  is below msg_rate limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (user_param.work_rdma_cm == ON) {
 		if (destroy_ctx(&ctx,&user_param)) {
 			fprintf(stderr, "Failed to destroy resources\n");
-			return 1;
+			goto free_dests;
 		}
 		user_comm.rdma_params->work_rdma_cm = ON;
+		free(my_dest);
+		free(rem_dest);
 		return destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params);
 	}
 
+	free(my_dest);
+	free(rem_dest);
 	return destroy_ctx(&ctx,&user_param);
+
+eexists:
+	ret_val = 17;
+destroy_ctx:
+	destroy_ctx(&ctx, &user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

PATCH 8/23 read_lat: fix assorted memory leaks on error paths

In reply to a message not in the archive

Leaks reported by clang/coverity.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/read_lat.c | 55 ++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 34 insertions(+), 21 deletions(-)
src/read_lat.c +34 -21
index 247c70d..1e63e87 100755
@@ -54,6 +54,7 @@
 int main(int argc, char *argv[])
 {
 	int                         ret_parser,i = 0;
+	int			    ret_val = FAILURE;
 	struct report_options       report;
 	struct pingpong_context     ctx;
 	struct ibv_device           *ib_dev;
@@ -95,7 +96,7 @@ int main(int argc, char *argv[])
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		return FAILURE;
 	}
 
 	/* See if MTU and link type are valid and supported. */
@@ -107,7 +108,7 @@ int main(int argc, char *argv[])
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm,&user_param)) {
 		fprintf(stderr," Unable to create RDMA_CM resources\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -146,17 +147,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx,&user_param)) {
 				fprintf(stderr," Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -165,14 +166,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources (data buffer, PD, MR, CQ and events channel) */
 		if (ctx_init(&ctx,&user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (set_up_connection(&ctx,&user_param,my_dest)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -184,7 +185,7 @@ int main(int argc, char *argv[])
 	/*  shaking hands and gather the other side info. */
 	if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	user_comm.rdma_params->side = REMOTE;
@@ -193,7 +194,7 @@ int main(int argc, char *argv[])
 		/* shaking hands and gather the other side info. */
 		if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		ctx_print_pingpong_data(&rem_dest[i],&user_comm);
@@ -203,7 +204,7 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr,"\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr," Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -211,14 +212,14 @@ int main(int argc, char *argv[])
 
 		if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	/* An additional handshake is required after moving qp to RTR. */
 	if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* Only Client post read request. */
@@ -226,19 +227,19 @@ int main(int argc, char *argv[])
 
 		if (ctx_close_connection(&user_comm,my_dest,rem_dest)) {
 			fprintf(stderr,"Failed to close connection between server and client\n");
-			return 1;
+			goto destroy_ctx;
 		}
 		if (user_param.output == FULL_VERBOSITY) {
 			printf(RESULT_LINE);
 		}
-		return 0;
+		goto out_success;
 
 	}
 
 	if (user_param.use_event) {
 		if (ibv_req_notify_cq(ctx.send_cq, 0)) {
 			fprintf(stderr, "Couldn't request CQ notification\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -253,25 +254,37 @@ int main(int argc, char *argv[])
 	if (user_param.test_method == RUN_ALL) {
 		for (i = 1; i < 24 ; ++i) {
 			user_param.size = (uint64_t)1 << i;
-			if(run_iter_lat(&ctx,&user_param))
-				return 17;
+			if(run_iter_lat(&ctx,&user_param)) {
+				ret_val = 17;
+				goto destroy_ctx;
+			}
 
 			user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param);
 		}
 	} else {
-		if(run_iter_lat(&ctx,&user_param))
-			return 18;
+		if(run_iter_lat(&ctx,&user_param)) {
+			ret_val = 18;
+			goto destroy_ctx;
+		}
 
 		user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param);
 	}
 
 	if (ctx_close_connection(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to close connection between server and client\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (user_param.output == FULL_VERBOSITY) {
 		printf(RESULT_LINE);
 	}
-	return 0;
+
+out_success:
+	ret_val = 0;
+destroy_ctx:
+	destroy_ctx(&ctx, &user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw

PATCH 9/23 write_bw: fix assorted memory leaks on error paths

In reply to a message not in the archive

Leaks all reported by clang/coverity.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/write_bw.c | 81 ++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 45 insertions(+), 36 deletions(-)
src/write_bw.c +45 -36
index 63422a8..1ee426c 100755
@@ -48,6 +48,7 @@
 int main(int argc, char *argv[])
 {
 	int				ret_parser,i = 0;
+	int				ret_val = FAILURE;
 	struct ibv_device		*ib_dev = NULL;
 	struct pingpong_context		ctx;
 	struct pingpong_dest		*my_dest,*rem_dest;
@@ -69,7 +70,7 @@ int main(int argc, char *argv[])
 	if (ret_parser) {
 		if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT)
 			fprintf(stderr," Parser function exited with Error\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if((user_param.connection_type == DC || user_param.use_xrc) && user_param.duplex) {
@@ -80,14 +81,14 @@ int main(int argc, char *argv[])
 	ib_dev = ctx_find_dev(user_param.ib_devname);
 	if (!ib_dev) {
 		fprintf(stderr," Unable to find the Infiniband/RoCE device\n");
-		return 1;
+		return FAILURE;
 	}
 
 	/* Getting the relevant context from the device */
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		return FAILURE;
 	}
 
 	/* See if MTU and link type are valid and supported. */
@@ -99,7 +100,7 @@ int main(int argc, char *argv[])
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm,&user_param)) {
 		fprintf(stderr," Unable to create RDMA_CM resources\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -138,17 +139,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx,&user_param)) {
 				fprintf(stderr," Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -157,14 +158,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources (data buffer, PD, MR, CQ and events channel) */
 		if (ctx_init(&ctx, &user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (set_up_connection(&ctx,&user_param,my_dest)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return FAILURE;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -181,7 +182,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) {
 			fprintf(stderr," Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		ctx_print_pingpong_data(&rem_dest[i],&user_comm);
@@ -191,21 +192,21 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr,"\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr," Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	if (user_param.work_rdma_cm == OFF) {
 		if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 	}
 
 	/* An additional handshake is required after moving qp to RTR. */
 	if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 		fprintf(stderr," Failed to exchange data between server and clients\n");
-		return FAILURE;
+		goto destroy_ctx;
 	}
 
 	if (user_param.output == FULL_VERBOSITY) {
@@ -226,7 +227,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr," Failed to exchange data between server and clients\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 
 		xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version));
@@ -234,7 +235,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr,"Failed to close connection between server and client\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		if (user_param.output == FULL_VERBOSITY) {
@@ -247,13 +248,15 @@ int main(int argc, char *argv[])
 		if (user_param.work_rdma_cm == ON) {
 			if (destroy_ctx(&ctx,&user_param)) {
 				fprintf(stderr, "Failed to destroy resources\n");
-				return 1;
+				goto free_dests;
 			}
 			user_comm.rdma_params->work_rdma_cm = ON;
-			return destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params);
+			ret_val = destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params);
+			goto free_dests;
 		}
 
-		return destroy_ctx(&ctx,&user_param);
+		ret_val = destroy_ctx(&ctx,&user_param);
+		goto free_dests;
 	}
 
 	if (user_param.test_method == RUN_ALL) {
@@ -265,25 +268,25 @@ int main(int argc, char *argv[])
 
 			if(perform_warm_up(&ctx,&user_param)) {
 				fprintf(stderr,"Problems with warm up\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
 			if(user_param.duplex) {
 				if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 					fprintf(stderr,"Failed to sync between server and client between different msg sizes\n");
-					return 1;
+					goto destroy_ctx;
 				}
 			}
 
 			if(run_iter_bw(&ctx,&user_param)) {
 				fprintf(stderr," Failed to complete run_iter_bw function successfully\n");
-				return 1;
+				goto destroy_ctx;
 			}
 
 			if (user_param.duplex && (atof(user_param.version) >= 4.6)) {
 				if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 					fprintf(stderr,"Failed to sync between server and client between different msg sizes\n");
-					return 1;
+					goto destroy_ctx;
 				}
 			}
 
@@ -302,20 +305,20 @@ int main(int argc, char *argv[])
 		if (user_param.verb != SEND) {
 			if(perform_warm_up(&ctx,&user_param)) {
 				fprintf(stderr,"Problems with warm up\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 
 		if(user_param.duplex) {
 			if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 				fprintf(stderr,"Failed to sync between server and client between different msg sizes\n");
-				return 1;
+				goto destroy_ctx;
 			}
 		}
 
 		if(run_iter_bw(&ctx,&user_param)) {
 			fprintf(stderr," Failed to complete run_iter_bw function successfully\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		print_report_bw(&user_param,&my_bw_rep);
@@ -346,7 +349,7 @@ int main(int argc, char *argv[])
 
 		if(run_iter_bw_infinitely(&ctx,&user_param)) {
 			fprintf(stderr," Error occured while running infinitely! aborting ...\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
@@ -362,7 +365,7 @@ int main(int argc, char *argv[])
 
 		if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) {
 			fprintf(stderr," Failed to exchange data between server and clients\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 
 		xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version));
@@ -371,30 +374,36 @@ int main(int argc, char *argv[])
 	/* Closing connection. */
 	if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) {
 		fprintf(stderr,"Failed to close connection between server and client\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (!user_param.is_bw_limit_passed && (user_param.is_limit_bw == ON ) ) {
 		fprintf(stderr,"Error: BW result is below bw limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	if (!user_param.is_msgrate_limit_passed && (user_param.is_limit_bw == ON )) {
 		fprintf(stderr,"Error: Msg rate  is below msg_rate limit\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
-	free(my_dest);
-	free(rem_dest);
-
 	if (user_param.work_rdma_cm == ON) {
 		if (destroy_ctx(&ctx,&user_param)) {
 			fprintf(stderr, "Failed to destroy resources\n");
-			return 1;
+			goto free_dests;
 		}
 		user_comm.rdma_params->work_rdma_cm = ON;
-		return destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params);
+		ret_val = destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params);
+		goto free_dests;
 	}
 
-	return destroy_ctx(&ctx,&user_param);
+	ret_val = destroy_ctx(&ctx,&user_param);
+	goto free_dests;
+
+destroy_ctx:
+	destroy_ctx(&ctx, &user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#11 lore raw

PATCH 10/23 write_lat: fix assorted memory leaks on error paths

In reply to a message not in the archive

Leaks reportedy by clang/coverity.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/write_lat.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)
src/write_lat.c +23 -15
index 4cb3e36..232ca14 100755
@@ -54,6 +54,7 @@
 int main(int argc, char *argv[])
 {
 	int				ret_parser,i = 0;
+	int				ret_val = FAILURE;
 	struct report_options		report;
 	struct pingpong_context		ctx;
 	struct pingpong_dest		*my_dest  = NULL;
@@ -95,7 +96,7 @@ int main(int argc, char *argv[])
 	ctx.context = ibv_open_device(ib_dev);
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
-		return 1;
+		return FAILURE;
 	}
 
 	/* See if MTU and link type are valid and supported. */
@@ -107,7 +108,7 @@ int main(int argc, char *argv[])
 	/* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */
 	if (create_comm_struct(&user_comm,&user_param)) {
 		fprintf(stderr," Unable to create RDMA_CM resources\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) {
@@ -146,17 +147,17 @@ int main(int argc, char *argv[])
 		if (user_param.machine == CLIENT) {
 			if (retry_rdma_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 
 		} else {
 			if (create_rdma_resources(&ctx,&user_param)) {
 				fprintf(stderr," Unable to create the rdma_resources\n");
-				return FAILURE;
+				goto free_dests;
 			}
 			if (rdma_server_connect(&ctx,&user_param)) {
 				fprintf(stderr,"Unable to perform rdma_client function\n");
-				return FAILURE;
+				goto free_dests;
 			}
 		}
 
@@ -165,14 +166,14 @@ int main(int argc, char *argv[])
 		/* create all the basic IB resources (data buffer, PD, MR, CQ and events channel) */
 		if (ctx_init(&ctx,&user_param)) {
 			fprintf(stderr, " Couldn't create IB resources\n");
-			return FAILURE;
+			goto free_dests;
 		}
 	}
 
 	/* Set up the Connection. */
 	if (set_up_connection(&ctx,&user_param,my_dest)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	/* Print basic test information. */
@@ -184,7 +185,7 @@ int main(int argc, char *argv[])
 	/* shaking hands and gather the other side info. */
 	if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	user_comm.rdma_params->side = REMOTE;
@@ -193,7 +194,7 @@ int main(int argc, char *argv[])
 		/* shaking hands and gather the other side info. */
 		if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) {
 			fprintf(stderr,"Failed to exchange data between server and clients\n");
-			return 1;
+			goto destroy_ctx;
 		}
 
 		ctx_print_pingpong_data(&rem_dest[i],&user_comm);
@@ -203,21 +204,21 @@ int main(int argc, char *argv[])
 		if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) {
 			fprintf(stderr,"\n Found Incompatibility issue with GID types.\n");
 			fprintf(stderr," Please Try to use a different IP version.\n\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	if (user_param.work_rdma_cm == OFF) {
 		if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
-			return 1;
+			goto destroy_ctx;
 		}
 	}
 
 	/* An additional handshake is required after moving qp to RTR. */
 	if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) {
 		fprintf(stderr,"Failed to exchange data between server and clients\n");
-		return 1;
+		goto destroy_ctx;
 	}
 
 	ctx_set_send_wqes(&ctx,&user_param,rem_dest);
@@ -234,7 +235,7 @@ int main(int argc, char *argv[])
 			user_param.size = (uint64_t)1 << i;
 			if(run_iter_lat_write(&ctx,&user_param)) {
 				fprintf(stderr,"Test exited with Error\n");
-				return FAILURE;
+				goto destroy_ctx;
 			}
 
 			user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param);
@@ -244,7 +245,7 @@ int main(int argc, char *argv[])
 
 		if(run_iter_lat_write(&ctx,&user_param)) {
 			fprintf(stderr,"Test exited with Error\n");
-			return FAILURE;
+			goto destroy_ctx;
 		}
 		user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param);
 	}
@@ -252,5 +253,12 @@ int main(int argc, char *argv[])
 	if (user_param.output == FULL_VERBOSITY) {
 		printf(RESULT_LINE);
 	}
-	return 0;
+	ret_val = 0;
+
+destroy_ctx:
+	destroy_ctx(&ctx, &user_param);
+free_dests:
+	free(my_dest);
+	free(rem_dest);
+	return ret_val;
 }
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw

PATCH 11/23 raw_ethernet_resources: fix possible NULL math

In reply to a message not in the archive

While unlikely to happen in reality, there are code paths that could be taken, where we have the case of X = NULL, then X = X + 1;. Fix 'em.

Error: FORWARD_NULL (CWE-476): [#def39]
perftest-3.0/src/raw_ethernet_resources.c:404: assign_zero: Assigning: "header_buff" = "NULL".
perftest-3.0/src/raw_ethernet_resources.c:419: alias_transfer: Assigning: "header_buff" = "header_buff + 20UL".
perftest-3.0/src/raw_ethernet_resources.c:421: var_deref_model: Passing null pointer "header_buff" to "gen_tcp_header", which dereferences it. perftest-3.0/src/raw_ethernet_resources.c:173:2: deref_parm_in_call: Function "memcpy" dereferences "TCP_header_buffer". [Note: The source code implementation of the function has been overridden by a builtin model.]

 #  419|   		header_buff = header_buff + sizeof(struct IP_V4_header);
 #  420|   		if (user_param->tcp)
 #  421|-> 			gen_tcp_header(header_buff, my_dest_info->port + flows_offset,
 #  422|   				       rem_dest_info->port + flows_offset);
 #  423|   		else

Error: FORWARD_NULL (CWE-476): [#def40]
perftest-3.0/src/raw_ethernet_resources.c:404: assign_zero: Assigning: "header_buff" = "NULL".
perftest-3.0/src/raw_ethernet_resources.c:419: alias_transfer: Assigning: "header_buff" = "header_buff + 20UL".
perftest-3.0/src/raw_ethernet_resources.c:424: var_deref_model: Passing null pointer "header_buff" to "gen_udp_header", which dereferences it. perftest-3.0/src/raw_ethernet_resources.c:156:2: deref_parm_in_call: Function "memcpy" dereferences "UDP_header_buffer". [Note: The source code implementation of the function has been overridden by a builtin model.]

 #  422|   				       rem_dest_info->port + flows_offset);
 #  423|   		else
 #  424|-> 			gen_udp_header(header_buff, my_dest_info->port + flows_offset,
 #  425|   				       rem_dest_info->port+ flows_offset, pkt_size);
 #  426|
CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/raw_ethernet_resources.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/raw_ethernet_resources.c +1 -1
index 3b1516e..d087cab 100755
@@ -406,11 +406,11 @@ void build_pkt_on_buffer(struct ETH_header* eth_header,
 	int is_udp_or_tcp = user_param->is_client_port && user_param->is_server_port;
 
 	gen_eth_header(eth_header, my_dest_info->mac, rem_dest_info->mac, eth_type);
+	header_buff = (void*)eth_header + sizeof(struct ETH_header);
 
 	if(have_ip_header) {
 		int offset = is_udp_or_tcp ? 0 : flows_offset;
 
-		header_buff = (void*)eth_header + sizeof(struct ETH_header);
 		gen_ip_header(header_buff, &my_dest_info->ip, &rem_dest_info->ip,
 			      ip_next_protocol, pkt_size, user_param->tos, offset);
 	}
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

PATCH 12/23 perftest_communication: fix gid_index2 copy-pasta

In reply to a message not in the archive

I believe this should be user_param->gid_index2 here.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_communication.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/perftest_communication.c +1 -1
index fd71436..d46d21e 100755
@@ -761,7 +761,7 @@ int set_up_connection(struct pingpong_context *ctx,
 				return 0;
 
 			if (user_param->use_gid_user) {
-				if (ibv_query_gid(ctx->context, user_param->ib_port2, user_param->gid_index, &temp_gid2))
+				if (ibv_query_gid(ctx->context, user_param->ib_port2, user_param->gid_index2, &temp_gid2))
 					return -1;
 			} else {
 				user_param->gid_index2 = get_best_gid_index(ctx, user_param, &attr, user_param->ib_port2);
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#14 lore raw

PATCH 13/23 perftest_communication: don't leak addrinfo

In reply to a message not in the archive

Error: RESOURCE_LEAK (CWE-772): [#def7]
perftest-3.0/src/perftest_communication.c:873: alloc_arg: "check_add_port" allocates memory that is stored into "res". perftest-3.0/src/perftest_resources.c:554:2: alloc_arg: "getaddrinfo" allocates memory that is stored into "*res". perftest-3.0/src/perftest_communication.c:879: leaked_storage: Variable "res" going out of scope leaks the storage it points to.

 #  877|
 #  878|   	if (res->ai_family != PF_INET) {
 #  879|-> 		return FAILURE;
 #  880|   	}
 #  881|

Error: RESOURCE_LEAK (CWE-772): [#def8]
perftest-3.0/src/perftest_communication.c:873: alloc_arg: "check_add_port" allocates memory that is stored into "res". perftest-3.0/src/perftest_resources.c:554:2: alloc_arg: "getaddrinfo" allocates memory that is stored into "*res". perftest-3.0/src/perftest_communication.c:889: leaked_storage: Variable "res" going out of scope leaks the storage it points to.

 #  887|   		if (num_of_retry == 0) {
 #  888|   			fprintf(stderr, "Received %d times ADDR_ERROR\n",NUM_OF_RETRIES);
 #  889|-> 			return FAILURE;
 #  890|   		}
 #  891|

(and more!)

This var is only accessed by the above referenced conditional, and to copy sin, just add two freeaddrinfo(res) calls and we should plug several possible leaks on error paths.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_communication.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/perftest_communication.c +4 -1
index d46d21e..bec973a 100755
@@ -876,11 +876,13 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
 	}
 
 	if (res->ai_family != PF_INET) {
+		freeaddrinfo(res);
 		return FAILURE;
 	}
 
 	memcpy(&sin, res->ai_addr, sizeof(sin));
 	sin.sin_port = htons((unsigned short)user_param->port);
+	freeaddrinfo(res);
 
 	while (1) {
 
@@ -1074,10 +1076,12 @@ int rdma_server_connect(struct pingpong_context *ctx,
 	}
 
 	if (res->ai_family != PF_INET) {
+		freeaddrinfo(res);
 		return FAILURE;
 	}
 	memcpy(&sin, res->ai_addr, sizeof(sin));
 	sin.sin_port = htons((unsigned short)user_param->port);
+	freeaddrinfo(res);
 
 	if (rdma_bind_addr(ctx->cm_id_control,(struct sockaddr *)&sin)) {
 		fprintf(stderr," rdma_bind_addr failed\n");
@@ -1160,7 +1164,6 @@ int rdma_server_connect(struct pingpong_context *ctx,
 
 	rdma_ack_cm_event(event);
 	rdma_destroy_id(ctx->cm_id_control);
-	freeaddrinfo(res);
 	return 0;
 }
 
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#15 lore raw

PATCH 14/23 perftest_communication: fix ibv_create_ah failure check

In reply to a message not in the archive

We've already dereferenced ctx->ah by assigning the return value of ibv_create_ah to ctx->ah[0], so this check as-is will currently never trip. I believe what was meant was to check for a failure of ibv_create_ah, which returns 0 on success or the value of errno on failure. Just check for non-zero ctx->ah[0] instead.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_communication.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/perftest_communication.c +1 -1
index bec973a..d938e41 100755
@@ -1007,7 +1007,7 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
 
 		ctx->ah[0] = ibv_create_ah(ctx->pd,&event->param.ud.ah_attr);
 
-		if (!ctx->ah) {
+		if (ctx->ah[0]) {
 			printf(" Unable to create address handler for UD QP\n");
 			return FAILURE;
 		}
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#16 lore raw

PATCH 15/23 perftest_communication: fix overflow w/size_of_cur=4

In reply to a message not in the archive

First up, we have rem[2] and cur[2], and then we figure out what to set size_of_cur to -- either 2 or 4. If it's 4 though... we then try to do a ctx_xchg_data() on rem and cur with a size of 4, which results in buffer overflows and memory corruption. Just make cur and rem size 4 instead.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_communication.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/perftest_communication.c +2 -2
index d938e41..b66801c 100755
@@ -1706,8 +1706,8 @@ void check_sys_data(struct perftest_comm *user_comm, struct perftest_parameters
  ******************************************************************************/
 int check_mtu(struct ibv_context *context,struct perftest_parameters *user_param, struct perftest_comm *user_comm) {
 	int curr_mtu=0, rem_mtu=0;
-	char cur[2];
-	char rem[2];
+	char cur[4];
+	char rem[4];
 	int size_of_cur;
 
 	if (user_param->connection_type == RawEth) {
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

PATCH 16/23 perftest: check for NULL fgets() returns

In reply to a message not in the archive

Check for fgets() failure in addition to fopen() failure and take appropriate action.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_parameters.c    | 5 ++++-
 src/perftest_resources.c     | 5 ++++-
 src/raw_ethernet_resources.c | 5 ++++-
 3 files changed, 12 insertions(+), 3 deletions(-)
src/perftest_parameters.c +4 -1
index e316143..32ebea9 100755
@@ -147,7 +147,10 @@ static int get_cache_line_size()
 		if (fp == NULL) {
 			return DEF_CACHE_LINE_SIZE;
 		}
-		fgets(line,10,fp);
+		if (fgets(line,10,fp) == NULL) {
+			fclose(fp);
+			return DEF_CACHE_LINE_SIZE;
+		}
 		size = atoi(line);
 		fclose(fp);
 	}
src/perftest_resources.c +4 -1
index 4dc0705..91c6d1e 100755
@@ -230,7 +230,10 @@ static void get_cpu_stats(struct perftest_parameters *duration_param,int stat_in
 	int index=0;
 	fp = fopen(file_name, "r");
 	if (fp != NULL) {
-		fgets(line,100,fp);
+		if (fgets(line,100,fp) == NULL) {
+			fclose(fp);
+			return;
+		}
 		compress_spaces(line,line);
 		index=get_n_word_string(line,tmp,index,2); /* skip first word */
 		duration_param->cpu_util_data.ustat[stat_index-1] = atoll(tmp);
src/raw_ethernet_resources.c +4 -1
index d087cab..22e1bab 100755
@@ -69,7 +69,10 @@ int check_flow_steering_support(char *dev_name)
 	fp = fopen(file_name, "r");
 	if (fp == NULL)
 		return 0;
-	fgets(line,4,fp);
+	if (fgets(line,4,fp) == NULL) {
+		fclose(fp);
+		return 0;
+	}
 
 	int val = atoi(line);
 	if (val >= 0) {
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#18 lore raw

PATCH 17/23 perftest_parameters: remove dead code in printf

In reply to a message not in the archive

If we can only get into this block of printf's when tst == BW, there's not much point in later testing to see if now tst == LAT. Remove pointless code.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_parameters.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/perftest_parameters.c +1 -1
index 32ebea9..b18588f 100755
@@ -311,7 +311,7 @@ static void usage(const char *argv0, VerbType verb, TestType tst, int connection
 
 	if (tst == BW) {
 		printf("  -t, --tx-depth=<dep> ");
-		printf(" Size of tx queue (default %d)\n",tst == LAT ? DEF_TX_LAT : DEF_TX_BW);
+		printf(" Size of tx queue (default %d)\n", DEF_TX_BW);
 	}
 
 	printf("  -T, --tos=<tos value> ");
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#19 lore raw

PATCH 18/23 perftest_resources: do 64-bit math setting tarr_size

In reply to a message not in the archive

Error: OVERFLOW_BEFORE_WIDEN: [#def28]
perftest-3.0/src/perftest_resources.c:650: overflow_before_widen: Potentially overflowing expression "user_param->iters * user_param->num_of_qps" with type "int" (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned). perftest-3.0/src/perftest_resources.c:650: remediation: To avoid overflow, cast either "user_param->iters" or "user_param->num_of_qps" to type "uint64_t".

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_resources.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/perftest_resources.c +1 -1
index 91c6d1e..7e982e9 100755
@@ -650,7 +650,7 @@ void alloc_ctx(struct pingpong_context *ctx,struct perftest_parameters *user_par
 
 	ALLOCATE(user_param->port_by_qp, uint64_t, user_param->num_of_qps);
 
-	tarr_size = (user_param->noPeak) ? 1 : user_param->iters*user_param->num_of_qps;
+	tarr_size = (user_param->noPeak) ? 1UL : (uint64_t)user_param->iters*user_param->num_of_qps;
 	ALLOCATE(user_param->tposted, cycles_t, tarr_size);
 	memset(user_param->tposted, 0, sizeof(cycles_t)*tarr_size);
 
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#20 lore raw

PATCH 19/23 perftest_resources: make sure num_of_qps is never 0

In reply to a message not in the archive

Somehow or another, if someone were to feed a 1 into num_of_qps, then we'd have num_of_qps = 1 / 2 = 0, and later on, portindex % 0 -- a divide by zero condition. Make sure that can't happen.

This resolves a coverity/clang warning.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_resources.c | 4 ++++
 1 file changed, 4 insertions(+)
src/perftest_resources.c +4 -0
index 7e982e9..959a5df 100755
@@ -1830,6 +1830,8 @@ int ctx_modify_dc_qp_to_init(struct ibv_qp *qp,struct perftest_parameters *user_
 
 	if (user_param->duplex || user_param->tst == LAT) {
 		num_of_qps /= 2;
+		if (num_of_qps < 2)
+			num_of_qps = 2;
 		num_of_qps_per_port = num_of_qps / 2;
 	}
 
@@ -1896,6 +1898,8 @@ int ctx_modify_qp_to_init(struct ibv_qp *qp,struct perftest_parameters *user_par
 
 	if ( user_param->use_xrc && (user_param->duplex || user_param->tst == LAT)) {
 		num_of_qps /= 2;
+		if (num_of_qps < 2)
+			num_of_qps = 2;
 		num_of_qps_per_port = num_of_qps / 2;
 	}
 
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#21 lore raw

PATCH 20/23 raw_ethernet_send_lat: prevent possible destroy on uninit val

In reply to a message not in the archive

Because user_param gets twiddled so much, coverity/clang think it could be possible for the value of user_param.flows to change over time, which could result in trying to call ibv_destroy_flow() on an uninitialized flow_create_result[i]. Just save user_param.flows to a local variable and use it for loop iterations to ensure consistency.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/raw_ethernet_send_lat.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
src/raw_ethernet_send_lat.c +12 -10
index 6d0bbf9..b6bce26 100755
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
 	struct ibv_flow_attr		**flow_rules;
 	#endif
 	struct report_options		report;
-	int				i;
+	int				i, flows;
 
 	/* allocate memory space for user parameters &*/
 	memset(&ctx,		0, sizeof(struct pingpong_context));
@@ -104,12 +104,13 @@ int main(int argc, char *argv[])
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
 		return FAILURE;
 	}
+	flows = user_param.flows;
 	#ifdef HAVE_RAW_ETH_EXP
-	ALLOCATE(flow_create_result, struct ibv_exp_flow*, user_param.flows);
-	ALLOCATE(flow_rules, struct ibv_exp_flow_attr*, user_param.flows);
+	ALLOCATE(flow_create_result, struct ibv_exp_flow*, flows);
+	ALLOCATE(flow_rules, struct ibv_exp_flow_attr*, flows);
 	#else
-	ALLOCATE(flow_create_result, struct ibv_flow*, user_param.flows);
-	ALLOCATE(flow_rules, struct ibv_flow_attr*, user_param.flows);
+	ALLOCATE(flow_create_result, struct ibv_flow*, flows);
+	ALLOCATE(flow_rules, struct ibv_flow_attr*, flows);
 	#endif
 
 
@@ -160,7 +161,7 @@ int main(int argc, char *argv[])
 	/* Print basic test information. */
 	ctx_print_test_info(&user_param);
 
-	for (i = 0; i < user_param.flows; i++)
+	for (i = 0; i < flows; i++)
 		print_spec(flow_rules[i], &user_param);
 
 	/* Create (if necessary) the rdma_cm ids and channel. */
@@ -196,7 +197,7 @@ int main(int argc, char *argv[])
 
 
 	/* attaching the qp to the spec */
-	for (i = 0; i < user_param.flows; i++) {
+	for (i = 0; i < flows; i++) {
 		#ifdef HAVE_RAW_ETH_EXP
 		flow_create_result[i] = ibv_exp_create_flow(ctx.qp[0], flow_rules[i]);
 		#else
@@ -274,7 +275,7 @@ int main(int argc, char *argv[])
 	#endif
 
 	/* destroy flow */
-	for (i = 0; i < user_param.flows; i++) {
+	for (i = 0; i < flows; i++) {
 		#ifdef HAVE_RAW_ETH_EXP
 		if (ibv_exp_destroy_flow(flow_create_result[i])) {
 		#else
@@ -292,14 +293,15 @@ int main(int argc, char *argv[])
 	if (destroy_ctx(&ctx, &user_param)) {
 		fprintf(stderr,"Failed to destroy_ctx\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return FAILURE;
+		goto free_flows;
 	}
 
 	if (user_param.output == FULL_VERBOSITY)
 		printf(RESULT_LINE);
 
 	DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-	return 0;
+	ret_val = SUCCESS;
+	goto free_flows;
 
 eexists:
 	ret_val = 17;
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#22 lore raw

PATCH 21/23 perftest_communication: check for error calling setsockopt()

In reply to a message not in the archive
CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_communication.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/perftest_communication.c +5 -1
index b66801c..6b3b1d9 100755
@@ -686,7 +686,11 @@ static int ethernet_server_connect(struct perftest_comm *comm)
 
 		if (sockfd >= 0) {
 			n = 1;
-			setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n);
+			if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n)) {
+				freeaddrinfo(res);
+				close(sockfd);
+				return 1;
+			}
 			if (!bind(sockfd, t->ai_addr, t->ai_addrlen))
 				break;
 			close(sockfd);
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#23 lore raw

PATCH 22/23 multicast_resources: use strncpy() to prevent overflow possibility

In reply to a message not in the archive
CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/multicast_resources.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/multicast_resources.c +1 -1
index 3a8edba..f5e4bea 100755
@@ -160,7 +160,7 @@ void set_multicast_gid(struct mcast_parameters *params,uint32_t qp_num,int is_cl
 		}
 		pstr += term - pstr + 1;
 
-		strcpy(tmp, pstr);
+		strncpy(tmp, pstr, sizeof(tmp) - 1);
 		mcg_gid[15] = (unsigned char)strtoll(tmp, NULL, 0);
 	}
 
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#24 lore raw

PATCH 23/23 perftest: replace 0/1 with SUCCESS/FAILURE

In reply to a message not in the archive

For consistency's sake, let's use the SUCCESS and FAILURE defines in returns everywhere we can.

CC Gil Rockah <gilr-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/perftest_communication.c | 156 +++++++++++++++++++++----------------------
 src/perftest_parameters.c    |  46 ++++++-------
 src/perftest_resources.c     | 104 ++++++++++++++---------------
 src/raw_ethernet_resources.c |  10 +--
 src/raw_ethernet_send_bw.c   |  26 ++++----
 src/send_bw.c                |  18 ++---
 src/send_lat.c               |  18 ++---
 7 files changed, 189 insertions(+), 189 deletions(-)
src/perftest_communication.c +78 -78
index 6b3b1d9..31ddb53 100755
@@ -73,7 +73,7 @@ strverscmp (const char *s1, const char *s2)
     };
 
   if (p1 == p2)
-    return 0;
+    return SUCCESS;
 
   c1 = *p1++;
   c2 = *p2++;
@@ -98,7 +98,7 @@ strverscmp (const char *s1, const char *s2)
     case LEN:
       while (isdigit (*p1++))
 	if (!isdigit (*p2++))
-	  return 1;
+	  return FAILURE;
 
       return isdigit (*p2) ? -1 : diff;
 
@@ -234,7 +234,7 @@ static int send_qp_num_for_ah(struct pingpong_context *ctx,
 
 	if (ibv_post_send(ctx->qp[0],&wr,&bad_wr)) {
 		fprintf(stderr, "Function ibv_post_send failed\n");
-		return 1;
+		return FAILURE;
 	}
 
 	do {
@@ -243,10 +243,10 @@ static int send_qp_num_for_ah(struct pingpong_context *ctx,
 
 	if (wc.status || wc.opcode != IBV_WC_SEND || wc.wr_id != 0) {
 		fprintf(stderr, " Couldn't post send my QP number %d\n",(int)wc.status);
-		return 1;
+		return FAILURE;
 	}
 
-	return 0;
+	return SUCCESS;
 
 }
 
@@ -267,7 +267,7 @@ static int create_ah_from_wc_recv(struct pingpong_context *ctx,
 
 	if (wc.status || !(wc.opcode & IBV_WC_RECV) || wc.wr_id != 0) {
 		fprintf(stderr, "Bad wc status when trying to create AH -- %d -- %d \n",(int)wc.status,(int)wc.wr_id);
-		return 1;
+		return FAILURE;
 	}
 
 	ctx->ah[0] = ibv_create_ah_from_wc(ctx->pd, &wc, (struct ibv_grh*)ctx->buf[0], ctx->cm_id->port_num);
@@ -275,7 +275,7 @@ static int create_ah_from_wc_recv(struct pingpong_context *ctx,
 	ibv_query_qp(ctx->qp[0],&attr, IBV_QP_QKEY,&init_attr);
 	user_param->rem_ud_qkey = attr.qkey;
 
-	return 0;
+	return SUCCESS;
 }
 
 
@@ -295,7 +295,7 @@ static int ethernet_write_keys(struct pingpong_dest *my_dest,
 		if (write(comm->rdma_params->sockfd,msg,sizeof msg) != sizeof msg) {
 			perror("client write");
 			fprintf(stderr, "Couldn't send local address\n");
-			return 1;
+			return FAILURE;
 		}
 
 	} else {
@@ -315,12 +315,12 @@ static int ethernet_write_keys(struct pingpong_dest *my_dest,
 		if (write(comm->rdma_params->sockfd, msg, sizeof msg) != sizeof msg) {
 			perror("client write");
 			fprintf(stderr, "Couldn't send local address\n");
-			return 1;
+			return FAILURE;
 		}
 
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -336,7 +336,7 @@ static int ethernet_read_keys(struct pingpong_dest *rem_dest,
 
 		if (read(comm->rdma_params->sockfd, msg, sizeof msg) != sizeof msg) {
 			fprintf(stderr, "ethernet_read_keys: Couldn't read remote address\n");
-			return 1;
+			return FAILURE;
 		}
 
 		parsed = sscanf(msg,KEY_PRINT_FMT,(unsigned int*)&rem_dest->lid,
@@ -345,7 +345,7 @@ static int ethernet_read_keys(struct pingpong_dest *rem_dest,
 
 		if (parsed != 7) {
 			fprintf(stderr, "Couldn't parse line <%.*s>\n",(int)sizeof msg, msg);
-			return 1;
+			return FAILURE;
 		}
 
 	} else {
@@ -357,7 +357,7 @@ static int ethernet_read_keys(struct pingpong_dest *rem_dest,
 
 		if (read(comm->rdma_params->sockfd, msg, sizeof msg) != sizeof msg) {
 			fprintf(stderr, "ethernet_read_keys: Couldn't read remote address\n");
-			return 1;
+			return FAILURE;
 		}
 
 		term = strpbrk(pstr, ":");
@@ -419,7 +419,7 @@ static int ethernet_read_keys(struct pingpong_dest *rem_dest,
 		rem_dest->srqn = (unsigned)strtoul(tmp, NULL, 16); /*SRQN*/
 
 	}
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -469,7 +469,7 @@ static int rdma_write_keys(struct pingpong_dest *my_dest,
 
 	if (ibv_post_send(comm->rdma_ctx->qp[0],&wr,&bad_wr)) {
 		fprintf(stderr, "Function ibv_post_send failed\n");
-		return 1;
+		return FAILURE;
 	}
 
 	do {
@@ -478,10 +478,10 @@ static int rdma_write_keys(struct pingpong_dest *my_dest,
 
 	if (wc.status || wc.opcode != IBV_WC_SEND || wc.wr_id != SYNC_SPEC_ID) {
 		fprintf(stderr, " Bad wc status %d\n",(int)wc.status);
-		return 1;
+		return FAILURE;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -502,7 +502,7 @@ static int rdma_read_keys(struct pingpong_dest *rem_dest,
 
 	if (wc.status || !(wc.opcode & IBV_WC_RECV) || wc.wr_id != SYNC_SPEC_ID) {
 		fprintf(stderr, "Bad wc status -- %d -- %d \n",(int)wc.status,(int)wc.wr_id);
-		return 1;
+		return FAILURE;
 	}
 
 	#ifdef HAVE_ENDIAN
@@ -521,10 +521,10 @@ static int rdma_read_keys(struct pingpong_dest *rem_dest,
 
 	if (post_one_recv_wqe(comm->rdma_ctx)) {
 		fprintf(stderr, "Couldn't post send \n");
-		return 1;
+		return FAILURE;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 
@@ -635,7 +635,7 @@ static int ethernet_client_connect(struct perftest_comm *comm)
 
 	if (check_add_port(&service,comm->rdma_params->port,comm->rdma_params->servername,&hints,&res)) {
 		fprintf(stderr, "Problem in resolving basic address and port\n");
-		return 1;
+		return FAILURE;
 	}
 
 	for (t = res; t; t = t->ai_next) {
@@ -653,11 +653,11 @@ static int ethernet_client_connect(struct perftest_comm *comm)
 
 	if (sockfd < 0) {
 		fprintf(stderr, "Couldn't connect to %s:%d\n",comm->rdma_params->servername,comm->rdma_params->port);
-		return 1;
+		return FAILURE;
 	}
 
 	comm->rdma_params->sockfd = sockfd;
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -678,7 +678,7 @@ static int ethernet_server_connect(struct perftest_comm *comm)
 
 	if (check_add_port(&service,comm->rdma_params->port,NULL,&hints,&res)) {
 		fprintf(stderr, "Problem in resolving basic adress and port\n");
-		return 1;
+		return FAILURE;
 	}
 
 	for (t = res; t; t = t->ai_next) {
@@ -689,7 +689,7 @@ static int ethernet_server_connect(struct perftest_comm *comm)
 			if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n)) {
 				freeaddrinfo(res);
 				close(sockfd);
-				return 1;
+				return FAILURE;
 			}
 			if (!bind(sockfd, t->ai_addr, t->ai_addrlen))
 				break;
@@ -701,7 +701,7 @@ static int ethernet_server_connect(struct perftest_comm *comm)
 
 	if (sockfd < 0) {
 		fprintf(stderr, "Couldn't listen to port %d\n", comm->rdma_params->port);
-		return 1;
+		return FAILURE;
 	}
 
 	listen(sockfd, 1);
@@ -711,11 +711,11 @@ static int ethernet_server_connect(struct perftest_comm *comm)
 		perror("server accept");
 		fprintf(stderr, "accept() failed\n");
 		close(sockfd);
-		return 1;
+		return FAILURE;
 	}
 	close(sockfd);
 	comm->rdma_params->sockfd = connfd;
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -745,7 +745,7 @@ int set_up_connection(struct pingpong_context *ctx,
 
 	if (user_param->gid_index != -1) {
 		if (ibv_query_port(ctx->context, user_param->ib_port, &attr))
-			return 0;
+			return SUCCESS;
 
 		if (user_param->use_gid_user) {
 			if (ibv_query_gid(ctx->context, user_param->ib_port, user_param->gid_index, &temp_gid))
@@ -762,7 +762,7 @@ int set_up_connection(struct pingpong_context *ctx,
 	if (user_param->dualport == ON) {
 		if (user_param->gid_index2 != -1) {
 			if (ibv_query_port(ctx->context, user_param->ib_port2, &attr))
-				return 0;
+				return SUCCESS;
 
 			if (user_param->use_gid_user) {
 				if (ibv_query_gid(ctx->context, user_param->ib_port2, user_param->gid_index2, &temp_gid2))
@@ -836,7 +836,7 @@ int set_up_connection(struct pingpong_context *ctx,
 		for (i=0; i < user_param->num_of_qps; i++) {
 			if (ibv_get_srq_num(ctx->srq,&(my_dest[i].srqn))) {
 				fprintf(stderr, "Couldn't get SRQ number\n");
-				return 1;
+				return FAILURE;
 			}
 		}
 	}
@@ -848,13 +848,13 @@ int set_up_connection(struct pingpong_context *ctx,
 			for (i=0; i < user_param->num_of_qps; i++) {
 				if (ibv_get_srq_num(ctx->srq, &(my_dest[i].srqn))) {
 					fprintf(stderr, "Couldn't get SRQ number\n");
-					return 1;
+					return FAILURE;
 				}
 			}
 		}
 	}
 	#endif
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -984,7 +984,7 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
 
 		if (post_one_recv_wqe(ctx)) {
 			fprintf(stderr, "Couldn't post send \n");
-			return 1;
+			return FAILURE;
 		}
 	}
 
@@ -1089,22 +1089,22 @@ int rdma_server_connect(struct pingpong_context *ctx,
 
 	if (rdma_bind_addr(ctx->cm_id_control,(struct sockaddr *)&sin)) {
 		fprintf(stderr," rdma_bind_addr failed\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (rdma_listen(ctx->cm_id_control,0)) {
 		fprintf(stderr, "rdma_listen failed\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (rdma_get_cm_event(ctx->cm_channel,&event)) {
 		fprintf(stderr, "rdma_get_cm_events failed\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (event->event != RDMA_CM_EVENT_CONNECT_REQUEST) {
 		fprintf(stderr, "bad event waiting for connect request %d\n",event->event);
-		return 1;
+		return FAILURE;
 	}
 
 	ctx->cm_id = (struct rdma_cm_id*)event->id;
@@ -1137,7 +1137,7 @@ int rdma_server_connect(struct pingpong_context *ctx,
 
 		if (post_one_recv_wqe(ctx)) {
 			fprintf(stderr, "Couldn't post send \n");
-			return 1;
+			return FAILURE;
 		}
 
 	} else if (user_param->connection_type == UD) {
@@ -1146,14 +1146,14 @@ int rdma_server_connect(struct pingpong_context *ctx,
 
 			if (post_recv_to_get_ah(ctx)) {
 				fprintf(stderr, "Couldn't post send \n");
-				return 1;
+				return FAILURE;
 			}
 		}
 	}
 
 	if (rdma_accept(ctx->cm_id, &conn_param)) {
 		fprintf(stderr, "Function rdma_accept failed\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param->work_rdma_cm && user_param->connection_type == UD) {
@@ -1161,14 +1161,14 @@ int rdma_server_connect(struct pingpong_context *ctx,
 		if (user_param->tst == LAT || (user_param->tst == BW && user_param->duplex)) {
 			if (create_ah_from_wc_recv(ctx,user_param)) {
 				fprintf(stderr, "Unable to create AH from WC\n");
-				return 1;
+				return FAILURE;
 			}
 		}
 	}
 
 	rdma_ack_cm_event(event);
 	rdma_destroy_id(ctx->cm_id_control);
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -1238,12 +1238,12 @@ int establish_connection(struct perftest_comm *comm)
 		if (comm->rdma_params->machine == CLIENT) {
 			if (rdma_client_connect(comm->rdma_ctx,comm->rdma_params)) {
 				fprintf(stderr," Unable to perform rdma_client function\n");
-				return 1;
+				return FAILURE;
 			}
 		} else {
 			if (rdma_server_connect(comm->rdma_ctx,comm->rdma_params)) {
 				fprintf(stderr," Unable to perform rdma_server function\n");
-				return 1;
+				return FAILURE;
 			}
 		}
 	} else {
@@ -1251,10 +1251,10 @@ int establish_connection(struct perftest_comm *comm)
 
 		if ((*ptr)(comm)) {
 			fprintf(stderr,"Unable to open file descriptor for socket connection");
-			return 1;
+			return FAILURE;
 		}
 	}
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -1281,11 +1281,11 @@ int ctx_hand_shake(struct perftest_comm *comm,
 	if (comm->rdma_params->servername) {
 		if ((*write_func_ptr)(my_dest,comm)) {
 			fprintf(stderr," Unable to write to socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 		if ((*read_func_ptr)(rem_dest,comm)) {
 			fprintf(stderr," Unable to read from socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 
 		/*Server side will wait for the client side to reach the write function.*/
@@ -1293,15 +1293,15 @@ int ctx_hand_shake(struct perftest_comm *comm,
 
 		if ((*read_func_ptr)(rem_dest,comm)) {
 			fprintf(stderr," Unable to read to socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 		if ((*write_func_ptr)(my_dest,comm)) {
 			fprintf(stderr," Unable to write from socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 
@@ -1318,12 +1318,12 @@ int ctx_xchg_data_ethernet( struct perftest_comm *comm,
 	if (comm->rdma_params->servername) {
 		if (ethernet_write_data(comm, (char *) my_data, size)) {
 			fprintf(stderr," Unable to write to socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 
 		if (ethernet_read_data(comm, (char *) rem_data, size)) {
 			fprintf(stderr," Unable to read from socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 
 		/*Server side will wait for the client side to reach the write function.*/
@@ -1331,15 +1331,15 @@ int ctx_xchg_data_ethernet( struct perftest_comm *comm,
 
 		if (ethernet_read_data(comm, (char *) rem_data, size)) {
 			fprintf(stderr," Unable to read to socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 
 		if (ethernet_write_data(comm, (char *) my_data, size)) {
 			fprintf(stderr," Unable to write from socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 	}
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -1352,12 +1352,12 @@ int ctx_xchg_data_rdma( struct perftest_comm *comm,
 	if (comm->rdma_params->servername) {
 		if (rdma_write_data(my_data,comm,size)) {
 			fprintf(stderr," Unable to write to socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 
 		if (rdma_read_data(rem_data,comm,size)) {
 			fprintf(stderr," Unable to read from socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 
 		/*Server side will wait for the client side to reach the write function.*/
@@ -1365,15 +1365,15 @@ int ctx_xchg_data_rdma( struct perftest_comm *comm,
 
 		if (rdma_read_data(rem_data,comm,size)) {
 			fprintf(stderr," Unable to read to socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 
 		if (rdma_write_data(my_data,comm,size)) {
 			fprintf(stderr," Unable to write from socket/rdam_cm\n");
-			return 1;
+			return FAILURE;
 		}
 	}
-	return 0;
+	return SUCCESS;
 }
 
 
@@ -1392,17 +1392,17 @@ int rdma_read_data(void *data,
 
 	if (wc.status || !(wc.opcode & IBV_WC_RECV) || wc.wr_id != SYNC_SPEC_ID) {
 		fprintf(stderr, "Bad wc status -- %d -- %d \n",(int)wc.status,(int)wc.wr_id);
-		return 1;
+		return FAILURE;
 	}
 
 	memcpy(data,comm->rdma_ctx->buf[0], size);
 
 	if (post_one_recv_wqe(comm->rdma_ctx)) {
 		fprintf(stderr, "Couldn't post send \n");
-		return 1;
+		return FAILURE;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -1431,7 +1431,7 @@ int rdma_write_data(void *data,
 
 	if (ibv_post_send(comm->rdma_ctx->qp[0],&wr,&bad_wr)) {
 		fprintf(stderr, "Function ibv_post_send failed\n");
-		return 1;
+		return FAILURE;
 	}
 
 	do {
@@ -1440,10 +1440,10 @@ int rdma_write_data(void *data,
 
 	if (wc.status || wc.opcode != IBV_WC_SEND || wc.wr_id != SYNC_SPEC_ID) {
 		fprintf(stderr, " Bad wc status %d\n",(int)wc.status);
-		return 1;
+		return FAILURE;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -1454,10 +1454,10 @@ int ethernet_write_data(struct perftest_comm *comm, char *msg, size_t size)
 	if (write(comm->rdma_params->sockfd, msg, size) != size) {
 		perror("client write");
 		fprintf(stderr, "Couldn't send reports\n");
-		return 1;
+		return FAILURE;
 	}
 
-	return 0;
+	return SUCCESS;
 
 }
 /******************************************************************************
@@ -1467,10 +1467,10 @@ int ethernet_read_data(struct perftest_comm *comm, char *recv_msg, size_t size)
 {
 	if (read(comm->rdma_params->sockfd, recv_msg, size) != size) {
 		fprintf(stderr, "ethernet_read_data: Couldn't read reports\n");
-		return 1;
+		return FAILURE;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 
@@ -1486,7 +1486,7 @@ int ctx_xchg_data( struct perftest_comm *comm,
 	else
 		ctx_xchg_data_ethernet(comm,my_data,rem_data,size);
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -1633,7 +1633,7 @@ int ctx_close_connection(struct perftest_comm *comm,
 {
 	/*Signal client is finished.*/
 	if (ctx_hand_shake(comm,my_dest,rem_dest)) {
-		return 1;
+		return FAILURE;
 	}
 
 	if (!comm->rdma_params->use_rdma_cm && !comm->rdma_params->work_rdma_cm) {
@@ -1645,10 +1645,10 @@ int ctx_close_connection(struct perftest_comm *comm,
 		}
 
 		close(comm->rdma_params->sockfd);
-		return 0;
+		return SUCCESS;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -1775,9 +1775,9 @@ int ctx_check_gid_compatibility(struct pingpong_dest *my_dest,
 	gid_type2 = ipv6_addr_v4mapped((struct in6_addr *)rem_dest->gid.raw);
 
 	if (gid_type1 != gid_type2)
-		return 1;
+		return FAILURE;
 
-	return 0;
+	return SUCCESS;
 }
 /******************************************************************************
  * End
src/perftest_parameters.c +23 -23

167 lines not on this page · raw message

src/perftest_resources.c +52 -52

386 lines not on this page · raw message

src/raw_ethernet_resources.c +5 -5
index 22e1bab..dfed47d 100755
@@ -64,14 +64,14 @@ int check_flow_steering_support(char *dev_name)
 	int is_flow_steering_supported = 0;
 
 	if (strstr(dev_name, "mlx5") != NULL)
-		return 0;
+		return SUCCESS;
 
 	fp = fopen(file_name, "r");
 	if (fp == NULL)
-		return 0;
+		return SUCCESS;
 	if (fgets(line,4,fp) == NULL) {
 		fclose(fp);
-		return 0;
+		return SUCCESS;
 	}
 
 	int val = atoi(line);
@@ -634,7 +634,7 @@ static int set_up_flow_rules(
 		spec_info->eth.mask.ether_type = 0xffff;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -695,7 +695,7 @@ int send_set_up_connection(
 			rem_dest_info->port = user_param->client_port;
 		}
 	}
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
src/raw_ethernet_send_bw.c +13 -13
index 89b8ba0..8d8dacb 100755
@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
 			fprintf(stderr," Parser function exited with Error\n");
 		}
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.raw_mcast) {
@@ -130,12 +130,12 @@ int main(int argc, char *argv[])
 	if (!ib_dev) {
 		fprintf(stderr," Unable to find the Infiniband/RoCE device\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		return FAILURE;
 	}
 	GET_STRING(user_param.ib_devname, ibv_get_device_name(ib_dev));
 
 	if (check_flow_steering_support(user_param.ib_devname)) {
-		return 1;
+		return FAILURE;
 	}
 
 	/* Getting the relevant context from the device */
@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
 	if (!ctx.context) {
 		fprintf(stderr, " Couldn't get context for the device\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		return FAILURE;
 	}
 
 	/* See if MTU and link type are valid and supported. */
@@ -159,7 +159,7 @@ int main(int argc, char *argv[])
 	/* set mac address by user choose */
 	if (send_set_up_connection(&flow_rules,&ctx,&user_param,&my_dest_info,&rem_dest_info)) {
 		fprintf(stderr," Unable to set up socket connection\n");
-		return 1;
+		return FAILURE;
 	}
 
 	/* Print basic test information. */
@@ -207,7 +207,7 @@ int main(int argc, char *argv[])
 		if (ctx_connect(&ctx,NULL,&user_param,NULL)) {
 			fprintf(stderr," Unable to Connect the HCA's through the link\n");
 			DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-			return 1;
+			return FAILURE;
 		}
 	}
 
@@ -277,7 +277,7 @@ int main(int argc, char *argv[])
 			if (ctx_set_recv_wqes(&ctx,&user_param)) {
 				fprintf(stderr," Failed to post receive recv_wqes\n");
 				DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-				return 1;
+				return FAILURE;
 			}
 		}
 
@@ -320,7 +320,7 @@ int main(int argc, char *argv[])
 
 			if (ctx_set_recv_wqes(&ctx,&user_param)) {
 				fprintf(stderr," Failed to post receive recv_wqes\n");
-				return 1;
+				return FAILURE;
 			}
 		}
 
@@ -328,14 +328,14 @@ int main(int argc, char *argv[])
 
 			if(run_iter_bw_infinitely(&ctx,&user_param)) {
 				fprintf(stderr," Error occured while running infinitely! aborting ...\n");
-				return 1;
+				return FAILURE;
 			}
 
 		} else if (user_param.machine == SERVER) {
 
 			if(run_iter_bw_infinitely_server(&ctx,&user_param)) {
 				fprintf(stderr," Error occured while running infinitely on server! aborting ...\n");
-				return 1;
+				return FAILURE;
 			}
 		}
 	}
@@ -374,18 +374,18 @@ int main(int argc, char *argv[])
 	if (destroy_ctx(&ctx, &user_param)) {
 		fprintf(stderr,"Failed to destroy_ctx\n");
 		DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-		return 1;
+		return FAILURE;
 	}
 
 	/* limit verifier */
 	if (!user_param.is_bw_limit_passed && (user_param.is_limit_bw == ON ) ) {
 		fprintf(stderr,"Error: BW result is below bw limit\n");
-		return 1;
+		return FAILURE;
 	}
 
 	if (user_param.output == FULL_VERBOSITY)
 		printf(RESULT_LINE);
 
 	DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__);
-	return 0;
+	return SUCCESS;
 }
src/send_bw.c +9 -9
index 45cbb67..e7caa18 100755
@@ -53,15 +53,15 @@ static int set_mcast_group(struct pingpong_context *ctx,
 	struct ibv_port_attr port_attr;
 
 	if (ibv_query_gid(ctx->context,user_param->ib_port,user_param->gid_index,&mcg_params->port_gid)) {
-		return 1;
+		return FAILURE;
 	}
 
 	if (ibv_query_pkey(ctx->context,user_param->ib_port,DEF_PKEY_IDX,&mcg_params->pkey)) {
-		return 1;
+		return FAILURE;
 	}
 
 	if (ibv_query_port(ctx->context,user_param->ib_port,&port_attr)) {
-		return 1;
+		return FAILURE;
 	}
 	mcg_params->sm_lid  = port_attr.sm_lid;
 	mcg_params->sm_sl   = port_attr.sm_sl;
@@ -71,10 +71,10 @@ static int set_mcast_group(struct pingpong_context *ctx,
 		/* Request for Mcast group create registery in SM. */
 		if (join_multicast_group(SUBN_ADM_METHOD_SET,mcg_params)) {
 			fprintf(stderr,"Couldn't Register the Mcast group on the SM\n");
-			return 1;
+			return FAILURE;
 		}
 	}
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -98,13 +98,13 @@ static int send_set_up_connection(struct pingpong_context *ctx,
 		mcg_params->user_mgid = user_param->user_mgid;
 		set_multicast_gid(mcg_params,ctx->qp[0]->qp_num,(int)user_param->machine);
 		if (set_mcast_group(ctx,user_param,mcg_params)) {
-			return 1;
+			return FAILURE;
 		}
 
 		for (i=0; i < user_param->num_of_qps; i++) {
 			if (ibv_attach_mcast(ctx->qp[i],&mcg_params->mgid,mcg_params->mlid)) {
 				fprintf(stderr, "Couldn't attach QP to MultiCast group");
-				return 1;
+				return FAILURE;
 			}
 		}
 
@@ -113,7 +113,7 @@ static int send_set_up_connection(struct pingpong_context *ctx,
 		my_dest->lid = mcg_params->mlid;
 		my_dest->qpn = QPNUM_MCAST;
 	}
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -581,7 +581,7 @@ int main(int argc, char *argv[])
 		goto destroy_ctx;
 	}
 
-	return 0;
+	return SUCCESS;
 
 destroy_ctx:
 	destroy_ctx(&ctx,&user_param);
src/send_lat.c +9 -9
index cc424c4..9d7b6bd 100755
@@ -61,15 +61,15 @@ static int set_mcast_group(struct pingpong_context *ctx,
 	struct ibv_port_attr port_attr;
 
 	if (ibv_query_gid(ctx->context,user_param->ib_port,user_param->gid_index,&mcg_params->port_gid)) {
-		return 1;
+		return FAILURE;
 	}
 
 	if (ibv_query_pkey(ctx->context,user_param->ib_port,DEF_PKEY_IDX,&mcg_params->pkey)) {
-		return 1;
+		return FAILURE;
 	}
 
 	if (ibv_query_port(ctx->context,user_param->ib_port,&port_attr)) {
-		return 1;
+		return FAILURE;
 	}
 	mcg_params->sm_lid  = port_attr.sm_lid;
 	mcg_params->sm_sl   = port_attr.sm_sl;
@@ -81,7 +81,7 @@ static int set_mcast_group(struct pingpong_context *ctx,
 		/* Request for Mcast group create registery in SM. */
 		if (join_multicast_group(SUBN_ADM_METHOD_SET,mcg_params)) {
 			fprintf(stderr," Failed to Join Mcast request\n");
-			return 1;
+			return FAILURE;
 		}
 	}
 
@@ -89,12 +89,12 @@ static int set_mcast_group(struct pingpong_context *ctx,
 
 		if (ibv_attach_mcast(ctx->qp[i],&mcg_params->mgid,mcg_params->mlid)) {
 			fprintf(stderr, "Couldn't attach QP to MultiCast group");
-			return 1;
+			return FAILURE;
 		}
 	}
 	mcg_params->mcast_state |= MCAST_IS_ATTACHED;
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
@@ -118,13 +118,13 @@ static int send_set_up_connection(struct pingpong_context *ctx,
 		mcg_params->user_mgid = user_param->user_mgid;
 		set_multicast_gid(mcg_params,ctx->qp[0]->qp_num,(int)user_param->machine);
 		if (set_mcast_group(ctx,user_param,mcg_params)) {
-			return 1;
+			return FAILURE;
 		}
 
 		for (i=0; i < user_param->num_of_qps; i++) {
 			if (ibv_attach_mcast(ctx->qp[i],&mcg_params->mgid,mcg_params->mlid)) {
 				fprintf(stderr, "Couldn't attach QP to MultiCast group");
-				return 1;
+				return FAILURE;
 			}
 		}
 
@@ -134,7 +134,7 @@ static int send_set_up_connection(struct pingpong_context *ctx,
 		my_dest->qpn = QPNUM_MCAST;
 	}
 
-	return 0;
+	return SUCCESS;
 }
 
 /******************************************************************************
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html