diff mbox series

[2.0,v1,2/5] linux-dpdk: changes which are needed for odp_crypto to work

Message ID 1512547207-1806-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [2.0,v1,1/5] test: enable dpdk initialization before running validation on linux-dpdk | expand

Commit Message

Github ODP bot Dec. 6, 2017, 8 a.m. UTC
From: Balakrishna Garapati <balakrishna.garapati@linaro.org>


All the changes are within the linux-dpdk/odp_crypto.c file:
1) Added missing brackets which made it impossible to create
   a crypto session
2) Increased the number of queues created, from nb_queue_pairs - 1
   to nb_queue_pairs, what seems to work better
3) Removed a memory leak - the memory allocated for iv and aad
   were not freed

Signed-off-by: Szymon Sliwa <szs@semihalf.com>

Signed-off-by: Balakrishna Garapati <balakrishna.garapati@linaro.org>

Reviewed-by: Yi He <yi.he@linaro.org>

---
/** Email created from pull request 323 (heyi-linaro:2.0-linux-dpdk-make-check)
 ** https://github.com/Linaro/odp/pull/323
 ** Patch: https://github.com/Linaro/odp/pull/323.patch
 ** Base sha: 00c7441fae53949dd87855d48102f932f8f64537
 ** Merge commit sha: 97e968c4c23266a903016fe9bda392687b44b08f
 **/
 platform/linux-dpdk/odp_crypto.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-dpdk/odp_crypto.c b/platform/linux-dpdk/odp_crypto.c
index 8e0f8a9df..9844f2dd7 100644
--- a/platform/linux-dpdk/odp_crypto.c
+++ b/platform/linux-dpdk/odp_crypto.c
@@ -271,7 +271,7 @@  int odp_crypto_init_global(void)
 
 		qp_conf.nb_descriptors = NB_MBUF;
 
-		for (queue_pair = 0; queue_pair < nb_queue_pairs - 1;
+		for (queue_pair = 0; queue_pair < nb_queue_pairs;
 							queue_pair++) {
 			rc = rte_cryptodev_queue_pair_setup(cdev_id,
 							    queue_pair,
@@ -898,11 +898,12 @@  int odp_crypto_session_create(odp_crypto_session_param_t *param,
 	/* Setup session */
 	session = rte_cryptodev_sym_session_create(cdev_id, first_xform);
 
-	if (session == NULL)
+	if (session == NULL) {
 		/* remove the crypto_session_entry_t */
 		memset(entry, 0, sizeof(*entry));
 		free_session(entry);
 		return -1;
+	}
 
 	entry->rte_session  = (intptr_t)session;
 	entry->cipher_xform = cipher_xform;
@@ -1216,6 +1217,9 @@  int odp_crypto_int(odp_packet_t pkt_in,
 		goto err;
 	}
 
+	op->sym->auth.aad.data = NULL;
+	op->sym->cipher.iv.data = NULL;
+
 	odp_spinlock_unlock(&global->lock);
 
 	/* Set crypto operation data parameters */
@@ -1242,9 +1246,8 @@  int odp_crypto_int(odp_packet_t pkt_in,
 	if (aad_len > 0) {
 		op->sym->auth.aad.data = rte_malloc("aad", aad_len, 0);
 		if (op->sym->auth.aad.data == NULL) {
-			rte_crypto_op_free(op);
 			ODP_ERR("Failed to allocate memory for AAD");
-			goto err;
+			goto err_op_free;
 		}
 
 		memcpy(op->sym->auth.aad.data, aad_head, aad_len);
@@ -1254,16 +1257,14 @@  int odp_crypto_int(odp_packet_t pkt_in,
 	}
 
 	if (entry->iv.length == 0) {
-		rte_crypto_op_free(op);
 		ODP_ERR("Wrong IV length");
-		goto err;
+		goto err_op_free;
 	}
 
 	op->sym->cipher.iv.data = rte_malloc("iv", entry->iv.length, 0);
 	if (op->sym->cipher.iv.data == NULL) {
-		rte_crypto_op_free(op);
 		ODP_ERR("Failed to allocate memory for IV");
-		goto err;
+		goto err_op_free;
 	}
 
 	if (param->override_iv_ptr) {
@@ -1300,18 +1301,16 @@  int odp_crypto_int(odp_packet_t pkt_in,
 		rc = rte_cryptodev_enqueue_burst(rte_session->dev_id,
 						 queue_pair, &op, 1);
 		if (rc == 0) {
-			rte_crypto_op_free(op);
 			ODP_ERR("Failed to enqueue packet");
-			goto err;
+			goto err_op_free;
 		}
 
 		rc = rte_cryptodev_dequeue_burst(rte_session->dev_id,
 						 queue_pair, &op, 1);
 
 		if (rc == 0) {
-			rte_crypto_op_free(op);
 			ODP_ERR("Failed to dequeue packet");
-			goto err;
+			goto err_op_free;
 		}
 
 		out_pkt = (odp_packet_t)op->sym->m_src;
@@ -1331,6 +1330,8 @@  int odp_crypto_int(odp_packet_t pkt_in,
 	op_result = get_op_result_from_packet(out_pkt);
 	*op_result = local_result;
 
+	rte_free(op->sym->cipher.iv.data);
+	rte_free(op->sym->auth.aad.data);
 	rte_crypto_op_free(op);
 
 	/* Synchronous, simply return results */
@@ -1338,6 +1339,11 @@  int odp_crypto_int(odp_packet_t pkt_in,
 
 	return 0;
 
+err_op_free:
+	rte_free(op->sym->cipher.iv.data);
+	rte_free(op->sym->auth.aad.data);
+	rte_crypto_op_free(op);
+
 err:
 	if (allocated) {
 		odp_packet_free(out_pkt);