diff mbox

[perftest,19/23] perftest_resources: make sure num_of_qps is never 0

Message ID 1471541538-20270-20-git-send-email-jarod@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jarod Wilson Aug. 18, 2016, 5:32 p.m. UTC
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@mellanox.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
---
 src/perftest_resources.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox

Patch

diff --git a/src/perftest_resources.c b/src/perftest_resources.c
index 7e982e9..959a5df 100755
--- a/src/perftest_resources.c
+++ b/src/perftest_resources.c
@@ -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;
 	}