DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] crypto/dpaa2_sec: improve error handling
@ 2020-05-04 20:39 Akhil Goyal
  2020-05-04 20:39 ` [dpdk-dev] [PATCH 2/2] crypto/dpaa_sec: " Akhil Goyal
  2020-05-04 21:39 ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Akhil Goyal
  0 siblings, 2 replies; 11+ messages in thread
From: Akhil Goyal @ 2020-05-04 20:39 UTC (permalink / raw)
  To: dev; +Cc: hemant.agrawal, Akhil Goyal

The return values in cases of errors were not
specified properly. With this patch appropriate
error numbers are returned.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
 drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 59 +++++++++++++--------
 1 file changed, 38 insertions(+), 21 deletions(-)

diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index 0919f3bf4..984c563e3 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -1814,7 +1814,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 {
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo cipherdata;
-	int bufsize;
+	int bufsize, ret = 0;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 
@@ -1826,7 +1826,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -1839,7 +1839,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	if (session->cipher_key.data == NULL) {
 		DPAA2_SEC_ERR("No Memory for cipher key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = xform->cipher.key.length;
 
@@ -1916,15 +1916,18 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_CIPHER_NULL:
 		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			xform->cipher.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			xform->cipher.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Descriptor build failed");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -1936,12 +1939,12 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	for (i = 0; i < bufsize; i++)
 		DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
 #endif
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
@@ -1951,7 +1954,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 {
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo authdata;
-	int bufsize;
+	int bufsize, ret = 0;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 
@@ -1964,7 +1967,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -1976,7 +1979,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 	if (session->auth_key.data == NULL) {
 		DPAA2_SEC_ERR("Unable to allocate memory for auth key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->auth_key.length = xform->auth.key.length;
 
@@ -2082,15 +2085,18 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AUTH_AES_CBC_MAC:
 		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
 			      xform->auth.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      xform->auth.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -2103,12 +2109,12 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 				i, priv->flc_desc[DESC_INITFINAL].desc[i]);
 #endif
 
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->auth_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
@@ -2123,7 +2129,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 	struct rte_crypto_aead_xform *aead_xform = &xform->aead;
-	int err;
+	int err, ret = 0;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2138,7 +2144,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -2149,7 +2155,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for aead key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	memcpy(session->aead_key.data, aead_xform->key.data,
 	       aead_xform->key.length);
@@ -2172,10 +2178,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AEAD_AES_CCM:
 		DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
 			      aead_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
 			      aead_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
@@ -2189,6 +2197,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 
 	if (err < 0) {
 		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+		ret = -EINVAL;
 		goto error_out;
 	}
 	if (priv->flc_desc[0].desc[1] & 1) {
@@ -2212,6 +2221,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 				session->digest_length);
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -2223,12 +2233,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 		DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
 			    i, priv->flc_desc[0].desc[i]);
 #endif
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->aead_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 
@@ -2244,7 +2254,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	struct sec_flow_context *flc;
 	struct rte_crypto_cipher_xform *cipher_xform;
 	struct rte_crypto_auth_xform *auth_xform;
-	int err;
+	int err, ret = 0;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2272,7 +2282,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -2283,7 +2293,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for cipher key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = cipher_xform->key.length;
 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
@@ -2292,7 +2302,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 		DPAA2_SEC_ERR("No Memory for auth key");
 		rte_free(session->cipher_key.data);
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->auth_key.length = auth_xform->key.length;
 	memcpy(session->cipher_key.data, cipher_xform->key.data,
@@ -2354,10 +2364,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
 		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	cipherdata.key = (size_t)session->cipher_key.data;
@@ -2389,10 +2401,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
 		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
@@ -2407,6 +2421,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 
 	if (err < 0) {
 		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+		ret = -EINVAL;
 		goto error_out;
 	}
 	if (priv->flc_desc[0].desc[2] & 1) {
@@ -2434,10 +2449,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 					      session->dir);
 		if (bufsize < 0) {
 			DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+			ret = -EINVAL;
 			goto error_out;
 		}
 	} else {
 		DPAA2_SEC_ERR("Hash before cipher not supported");
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
@@ -2450,13 +2467,13 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 			    i, priv->flc_desc[0].desc[i]);
 #endif
 
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(session->auth_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH 2/2] crypto/dpaa_sec: improve error handling
  2020-05-04 20:39 [dpdk-dev] [PATCH 1/2] crypto/dpaa2_sec: improve error handling Akhil Goyal
@ 2020-05-04 20:39 ` Akhil Goyal
  2020-05-04 21:39 ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Akhil Goyal
  1 sibling, 0 replies; 11+ messages in thread
From: Akhil Goyal @ 2020-05-04 20:39 UTC (permalink / raw)
  To: dev; +Cc: hemant.agrawal, Akhil Goyal

The return values in cases of errors were not
specified properly. With this patch appropriate
error numbers are returned.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
 drivers/crypto/dpaa_sec/dpaa_sec.c | 33 ++++++++++++++++--------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/crypto/dpaa_sec/dpaa_sec.c b/drivers/crypto/dpaa_sec/dpaa_sec.c
index a11b17bda..c8110aa50 100644
--- a/drivers/crypto/dpaa_sec/dpaa_sec.c
+++ b/drivers/crypto/dpaa_sec/dpaa_sec.c
@@ -2041,7 +2041,7 @@ dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      xform->cipher.algo);
 		rte_free(session->cipher_key.data);
-		return -1;
+		return -ENOTSUP;
 	}
 	session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
 			DIR_ENC : DIR_DEC;
@@ -2109,7 +2109,7 @@ dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
 			      xform->auth.algo);
 		rte_free(session->auth_key.data);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
@@ -2126,6 +2126,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 
 	struct rte_crypto_cipher_xform *cipher_xform;
 	struct rte_crypto_auth_xform *auth_xform;
+	int ret = 0;
 
 	session->ctxt = DPAA_SEC_CIPHER_HASH;
 	if (session->auth_cipher_text) {
@@ -2144,7 +2145,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 					       RTE_CACHE_LINE_SIZE);
 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
 		DPAA_SEC_ERR("No Memory for cipher key");
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = cipher_xform->key.length;
 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
@@ -2191,6 +2192,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
@@ -2212,16 +2214,17 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
 				DIR_ENC : DIR_DEC;
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(session->auth_key.data);
-	return -1;
+	return ret;
 }
 
 static int
@@ -2254,7 +2257,7 @@ dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg);
 		rte_free(session->aead_key.data);
-		return -ENOMEM;
+		return -ENOTSUP;
 	}
 
 	session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
@@ -2501,7 +2504,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 					       RTE_CACHE_LINE_SIZE);
 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
 		DPAA_SEC_ERR("No Memory for aead key");
-		return -1;
+		return -ENOMEM;
 	}
 	memcpy(session->aead_key.data, aead_xform->key.data,
 	       aead_xform->key.length);
@@ -2524,7 +2527,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 		default:
 			DPAA_SEC_ERR("Crypto: Undefined GCM digest %d",
 				     session->digest_length);
-			return -1;
+			return -EINVAL;
 		}
 		if (session->dir == DIR_ENC) {
 			memcpy(session->encap_pdb.gcm.salt,
@@ -2539,7 +2542,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined AEAD specified %u",
 			      aead_xform->algo);
-		return -1;
+		return -ENOTSUP;
 	}
 	return 0;
 }
@@ -2636,11 +2639,11 @@ dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
 		DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	switch (session->cipher_alg) {
@@ -2673,11 +2676,11 @@ dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
 		DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	return 0;
@@ -2893,7 +2896,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 		default:
 			DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 				      session->cipher_alg);
-			return -1;
+			return -EINVAL;
 		}
 
 		session->cipher_key.data = rte_zmalloc(NULL,
@@ -2944,7 +2947,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 			DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
 				      session->auth_alg);
 			rte_free(session->cipher_key.data);
-			return -1;
+			return -EINVAL;
 		}
 		session->auth_key.data = rte_zmalloc(NULL,
 						     auth_xform->key.length,
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: improve error handling
  2020-05-04 20:39 [dpdk-dev] [PATCH 1/2] crypto/dpaa2_sec: improve error handling Akhil Goyal
  2020-05-04 20:39 ` [dpdk-dev] [PATCH 2/2] crypto/dpaa_sec: " Akhil Goyal
@ 2020-05-04 21:39 ` Akhil Goyal
  2020-05-04 21:39   ` [dpdk-dev] [PATCH v2 2/2] crypto/dpaa_sec: " Akhil Goyal
                     ` (2 more replies)
  1 sibling, 3 replies; 11+ messages in thread
From: Akhil Goyal @ 2020-05-04 21:39 UTC (permalink / raw)
  To: dev; +Cc: hemant.agrawal, Akhil Goyal

The return values in cases of errors were not
specified properly. With this patch appropriate
error numbers are returned.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
 drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 59 +++++++++++++--------
 1 file changed, 38 insertions(+), 21 deletions(-)

diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index 0919f3bf4..984c563e3 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -1814,7 +1814,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 {
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo cipherdata;
-	int bufsize;
+	int bufsize, ret = 0;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 
@@ -1826,7 +1826,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -1839,7 +1839,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	if (session->cipher_key.data == NULL) {
 		DPAA2_SEC_ERR("No Memory for cipher key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = xform->cipher.key.length;
 
@@ -1916,15 +1916,18 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_CIPHER_NULL:
 		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			xform->cipher.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			xform->cipher.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Descriptor build failed");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -1936,12 +1939,12 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	for (i = 0; i < bufsize; i++)
 		DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
 #endif
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
@@ -1951,7 +1954,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 {
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo authdata;
-	int bufsize;
+	int bufsize, ret = 0;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 
@@ -1964,7 +1967,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -1976,7 +1979,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 	if (session->auth_key.data == NULL) {
 		DPAA2_SEC_ERR("Unable to allocate memory for auth key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->auth_key.length = xform->auth.key.length;
 
@@ -2082,15 +2085,18 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AUTH_AES_CBC_MAC:
 		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
 			      xform->auth.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      xform->auth.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -2103,12 +2109,12 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 				i, priv->flc_desc[DESC_INITFINAL].desc[i]);
 #endif
 
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->auth_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
@@ -2123,7 +2129,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 	struct rte_crypto_aead_xform *aead_xform = &xform->aead;
-	int err;
+	int err, ret = 0;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2138,7 +2144,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -2149,7 +2155,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for aead key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	memcpy(session->aead_key.data, aead_xform->key.data,
 	       aead_xform->key.length);
@@ -2172,10 +2178,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AEAD_AES_CCM:
 		DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
 			      aead_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
 			      aead_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
@@ -2189,6 +2197,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 
 	if (err < 0) {
 		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+		ret = -EINVAL;
 		goto error_out;
 	}
 	if (priv->flc_desc[0].desc[1] & 1) {
@@ -2212,6 +2221,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 				session->digest_length);
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -2223,12 +2233,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 		DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
 			    i, priv->flc_desc[0].desc[i]);
 #endif
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->aead_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 
@@ -2244,7 +2254,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	struct sec_flow_context *flc;
 	struct rte_crypto_cipher_xform *cipher_xform;
 	struct rte_crypto_auth_xform *auth_xform;
-	int err;
+	int err, ret = 0;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2272,7 +2282,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -2283,7 +2293,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for cipher key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = cipher_xform->key.length;
 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
@@ -2292,7 +2302,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 		DPAA2_SEC_ERR("No Memory for auth key");
 		rte_free(session->cipher_key.data);
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->auth_key.length = auth_xform->key.length;
 	memcpy(session->cipher_key.data, cipher_xform->key.data,
@@ -2354,10 +2364,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
 		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	cipherdata.key = (size_t)session->cipher_key.data;
@@ -2389,10 +2401,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
 		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
@@ -2407,6 +2421,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 
 	if (err < 0) {
 		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+		ret = -EINVAL;
 		goto error_out;
 	}
 	if (priv->flc_desc[0].desc[2] & 1) {
@@ -2434,10 +2449,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 					      session->dir);
 		if (bufsize < 0) {
 			DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+			ret = -EINVAL;
 			goto error_out;
 		}
 	} else {
 		DPAA2_SEC_ERR("Hash before cipher not supported");
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
@@ -2450,13 +2467,13 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 			    i, priv->flc_desc[0].desc[i]);
 #endif
 
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(session->auth_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 2/2] crypto/dpaa_sec: improve error handling
  2020-05-04 21:39 ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Akhil Goyal
@ 2020-05-04 21:39   ` Akhil Goyal
  2020-05-05  1:17   ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Lukasz Wojciechowski
  2020-05-09 22:22   ` [dpdk-dev] [PATCH v3 " Akhil Goyal
  2 siblings, 0 replies; 11+ messages in thread
From: Akhil Goyal @ 2020-05-04 21:39 UTC (permalink / raw)
  To: dev; +Cc: hemant.agrawal, Akhil Goyal

The return values in cases of errors were not
specified properly. With this patch appropriate
error numbers are returned.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
 drivers/crypto/dpaa_sec/dpaa_sec.c | 40 ++++++++++++++++--------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/drivers/crypto/dpaa_sec/dpaa_sec.c b/drivers/crypto/dpaa_sec/dpaa_sec.c
index a11b17bda..0ee21319a 100644
--- a/drivers/crypto/dpaa_sec/dpaa_sec.c
+++ b/drivers/crypto/dpaa_sec/dpaa_sec.c
@@ -2041,7 +2041,7 @@ dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      xform->cipher.algo);
 		rte_free(session->cipher_key.data);
-		return -1;
+		return -ENOTSUP;
 	}
 	session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
 			DIR_ENC : DIR_DEC;
@@ -2109,7 +2109,7 @@ dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
 			      xform->auth.algo);
 		rte_free(session->auth_key.data);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
@@ -2126,6 +2126,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 
 	struct rte_crypto_cipher_xform *cipher_xform;
 	struct rte_crypto_auth_xform *auth_xform;
+	int ret = 0;
 
 	session->ctxt = DPAA_SEC_CIPHER_HASH;
 	if (session->auth_cipher_text) {
@@ -2144,7 +2145,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 					       RTE_CACHE_LINE_SIZE);
 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
 		DPAA_SEC_ERR("No Memory for cipher key");
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = cipher_xform->key.length;
 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
@@ -2191,6 +2192,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
@@ -2212,16 +2214,17 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
 				DIR_ENC : DIR_DEC;
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(session->auth_key.data);
-	return -1;
+	return ret;
 }
 
 static int
@@ -2254,7 +2257,7 @@ dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg);
 		rte_free(session->aead_key.data);
-		return -ENOMEM;
+		return -ENOTSUP;
 	}
 
 	session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
@@ -2368,7 +2371,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 				ret = dpaa_sec_chain_init(dev, xform, session);
 		} else {
 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
-			return -EINVAL;
+			return -ENOTSUP;
 		}
 	/* Authenticate then Cipher */
 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
@@ -2384,7 +2387,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 				ret = dpaa_sec_chain_init(dev, xform, session);
 		} else {
 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
-			return -EINVAL;
+			return -ENOTSUP;
 		}
 
 	/* AEAD operation for AES-GCM kind of Algorithms */
@@ -2407,6 +2410,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 		if (session->inq[i] == NULL) {
 			DPAA_SEC_ERR("unable to attach sec queue");
 			rte_spinlock_unlock(&internals->lock);
+			ret = -EBUSY;
 			goto err1;
 		}
 	}
@@ -2419,7 +2423,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 	rte_free(session->auth_key.data);
 	memset(session, 0, sizeof(dpaa_sec_session));
 
-	return -EINVAL;
+	return ret;
 }
 
 static int
@@ -2501,7 +2505,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 					       RTE_CACHE_LINE_SIZE);
 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
 		DPAA_SEC_ERR("No Memory for aead key");
-		return -1;
+		return -ENOMEM;
 	}
 	memcpy(session->aead_key.data, aead_xform->key.data,
 	       aead_xform->key.length);
@@ -2524,7 +2528,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 		default:
 			DPAA_SEC_ERR("Crypto: Undefined GCM digest %d",
 				     session->digest_length);
-			return -1;
+			return -EINVAL;
 		}
 		if (session->dir == DIR_ENC) {
 			memcpy(session->encap_pdb.gcm.salt,
@@ -2539,7 +2543,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined AEAD specified %u",
 			      aead_xform->algo);
-		return -1;
+		return -ENOTSUP;
 	}
 	return 0;
 }
@@ -2636,11 +2640,11 @@ dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
 		DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	switch (session->cipher_alg) {
@@ -2673,11 +2677,11 @@ dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
 		DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	return 0;
@@ -2893,7 +2897,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 		default:
 			DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 				      session->cipher_alg);
-			return -1;
+			return -EINVAL;
 		}
 
 		session->cipher_key.data = rte_zmalloc(NULL,
@@ -2944,7 +2948,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 			DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
 				      session->auth_alg);
 			rte_free(session->cipher_key.data);
-			return -1;
+			return -EINVAL;
 		}
 		session->auth_key.data = rte_zmalloc(NULL,
 						     auth_xform->key.length,
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: improve error handling
  2020-05-04 21:39 ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Akhil Goyal
  2020-05-04 21:39   ` [dpdk-dev] [PATCH v2 2/2] crypto/dpaa_sec: " Akhil Goyal
@ 2020-05-05  1:17   ` Lukasz Wojciechowski
  2020-05-05 13:47     ` Akhil Goyal
  2020-05-09 22:22   ` [dpdk-dev] [PATCH v3 " Akhil Goyal
  2 siblings, 1 reply; 11+ messages in thread
From: Lukasz Wojciechowski @ 2020-05-05  1:17 UTC (permalink / raw)
  To: Akhil Goyal, dev; +Cc: hemant.agrawal


W dniu 04.05.2020 o 23:39, Akhil Goyal pisze:
> The return values in cases of errors were not
> specified properly. With this patch appropriate
> error numbers are returned.
>
> Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
> ---
>   drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 59 +++++++++++++--------
>   1 file changed, 38 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
> index 0919f3bf4..984c563e3 100644
> --- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
> +++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
> @@ -1814,7 +1814,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
>   {
>   	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
>   	struct alginfo cipherdata;
> -	int bufsize;
> +	int bufsize, ret = 0;
>   	struct ctxt_priv *priv;
>   	struct sec_flow_context *flc;
>   
> @@ -1826,7 +1826,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
>   			RTE_CACHE_LINE_SIZE);
>   	if (priv == NULL) {
>   		DPAA2_SEC_ERR("No Memory for priv CTXT");
> -		return -1;
> +		return -ENOMEM;
>   	}
>   
>   	priv->fle_pool = dev_priv->fle_pool;
> @@ -1839,7 +1839,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
>   	if (session->cipher_key.data == NULL) {
>   		DPAA2_SEC_ERR("No Memory for cipher key");
>   		rte_free(priv);
> -		return -1;
> +		return -ENOMEM;
>   	}
>   	session->cipher_key.length = xform->cipher.key.length;
>   
> @@ -1916,15 +1916,18 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
>   	case RTE_CRYPTO_CIPHER_NULL:
>   		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
>   			xform->cipher.algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	default:
>   		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
>   			xform->cipher.algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	}
>   
>   	if (bufsize < 0) {
>   		DPAA2_SEC_ERR("Crypto: Descriptor build failed");
> +		ret = -EINVAL;
>   		goto error_out;
>   	}
>   
> @@ -1936,12 +1939,12 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
>   	for (i = 0; i < bufsize; i++)
>   		DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
>   #endif
> -	return 0;
> +	return ret;
>   
>   error_out:
>   	rte_free(session->cipher_key.data);
>   	rte_free(priv);
> -	return -1;
> +	return ret;
>   }
>   
>   static int
> @@ -1951,7 +1954,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
>   {
>   	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
>   	struct alginfo authdata;
> -	int bufsize;
> +	int bufsize, ret = 0;
>   	struct ctxt_priv *priv;
>   	struct sec_flow_context *flc;
>   
> @@ -1964,7 +1967,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
>   			RTE_CACHE_LINE_SIZE);
>   	if (priv == NULL) {
>   		DPAA2_SEC_ERR("No Memory for priv CTXT");
> -		return -1;
> +		return -ENOMEM;
>   	}
>   
>   	priv->fle_pool = dev_priv->fle_pool;
> @@ -1976,7 +1979,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
>   	if (session->auth_key.data == NULL) {
>   		DPAA2_SEC_ERR("Unable to allocate memory for auth key");
>   		rte_free(priv);
> -		return -1;
> +		return -ENOMEM;
>   	}
>   	session->auth_key.length = xform->auth.key.length;
>   
> @@ -2082,15 +2085,18 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
>   	case RTE_CRYPTO_AUTH_AES_CBC_MAC:
>   		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
>   			      xform->auth.algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	default:
>   		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
>   			      xform->auth.algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	}
>   
>   	if (bufsize < 0) {
>   		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
> +		ret = -EINVAL;
>   		goto error_out;
>   	}
>   
> @@ -2103,12 +2109,12 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
>   				i, priv->flc_desc[DESC_INITFINAL].desc[i]);
>   #endif
>   
> -	return 0;
> +	return ret;
>   
>   error_out:
>   	rte_free(session->auth_key.data);
>   	rte_free(priv);
> -	return -1;
> +	return ret;
>   }
>   
>   static int
> @@ -2123,7 +2129,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
>   	struct ctxt_priv *priv;
>   	struct sec_flow_context *flc;
>   	struct rte_crypto_aead_xform *aead_xform = &xform->aead;
> -	int err;
> +	int err, ret = 0;
>   
>   	PMD_INIT_FUNC_TRACE();
>   
> @@ -2138,7 +2144,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
>   			RTE_CACHE_LINE_SIZE);
>   	if (priv == NULL) {
>   		DPAA2_SEC_ERR("No Memory for priv CTXT");
> -		return -1;
> +		return -ENOMEM;
>   	}
>   
>   	priv->fle_pool = dev_priv->fle_pool;
> @@ -2149,7 +2155,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
>   	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
>   		DPAA2_SEC_ERR("No Memory for aead key");
>   		rte_free(priv);
> -		return -1;
> +		return -ENOMEM;
>   	}
>   	memcpy(session->aead_key.data, aead_xform->key.data,
>   	       aead_xform->key.length);
> @@ -2172,10 +2178,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
>   	case RTE_CRYPTO_AEAD_AES_CCM:
>   		DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
>   			      aead_xform->algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	default:
>   		DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
>   			      aead_xform->algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	}
>   	session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
> @@ -2189,6 +2197,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
>   
>   	if (err < 0) {
>   		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
> +		ret = -EINVAL;
>   		goto error_out;
>   	}
>   	if (priv->flc_desc[0].desc[1] & 1) {
> @@ -2212,6 +2221,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
>   				session->digest_length);
>   	if (bufsize < 0) {
>   		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
> +		ret = -EINVAL;
>   		goto error_out;
>   	}
>   
> @@ -2223,12 +2233,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
>   		DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
>   			    i, priv->flc_desc[0].desc[i]);
>   #endif
> -	return 0;
> +	return ret;
>   
>   error_out:
>   	rte_free(session->aead_key.data);
>   	rte_free(priv);
> -	return -1;
> +	return ret;
>   }
>   
>   
> @@ -2244,7 +2254,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   	struct sec_flow_context *flc;
>   	struct rte_crypto_cipher_xform *cipher_xform;
>   	struct rte_crypto_auth_xform *auth_xform;
> -	int err;
> +	int err, ret = 0;
>   
>   	PMD_INIT_FUNC_TRACE();
>   
> @@ -2272,7 +2282,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   			RTE_CACHE_LINE_SIZE);
>   	if (priv == NULL) {
>   		DPAA2_SEC_ERR("No Memory for priv CTXT");
> -		return -1;
> +		return -ENOMEM;
>   	}
>   
>   	priv->fle_pool = dev_priv->fle_pool;
> @@ -2283,7 +2293,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
>   		DPAA2_SEC_ERR("No Memory for cipher key");
>   		rte_free(priv);
> -		return -1;
> +		return -ENOMEM;
>   	}
>   	session->cipher_key.length = cipher_xform->key.length;
>   	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
> @@ -2292,7 +2302,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   		DPAA2_SEC_ERR("No Memory for auth key");
>   		rte_free(session->cipher_key.data);
>   		rte_free(priv);
> -		return -1;
> +		return -ENOMEM;
>   	}
>   	session->auth_key.length = auth_xform->key.length;
>   	memcpy(session->cipher_key.data, cipher_xform->key.data,
> @@ -2354,10 +2364,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   	case RTE_CRYPTO_AUTH_ZUC_EIA3:
>   		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
>   			      auth_xform->algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	default:
>   		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
>   			      auth_xform->algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	}
>   	cipherdata.key = (size_t)session->cipher_key.data;
> @@ -2389,10 +2401,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   	case RTE_CRYPTO_CIPHER_KASUMI_F8:
>   		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
>   			      cipher_xform->algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	default:
>   		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
>   			      cipher_xform->algo);
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	}
>   	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
> @@ -2407,6 +2421,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   
>   	if (err < 0) {
>   		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
> +		ret = -EINVAL;
>   		goto error_out;
>   	}
>   	if (priv->flc_desc[0].desc[2] & 1) {
> @@ -2434,10 +2449,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   					      session->dir);
>   		if (bufsize < 0) {
>   			DPAA2_SEC_ERR("Crypto: Invalid buffer length");
> +			ret = -EINVAL;
>   			goto error_out;
>   		}
>   	} else {
>   		DPAA2_SEC_ERR("Hash before cipher not supported");
> +		ret = -ENOTSUP;
>   		goto error_out;
>   	}
>   
> @@ -2450,13 +2467,13 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
>   			    i, priv->flc_desc[0].desc[i]);
>   #endif
>   
> -	return 0;
> +	return ret;
>   
>   error_out:
>   	rte_free(session->cipher_key.data);
>   	rte_free(session->auth_key.data);
>   	rte_free(priv);
> -	return -1;
> +	return ret;
>   }
>   
>   static int

Hi Akhil,

There are still few places, where returned error code is not set.
Maybe you can add those places to your patch?

Here's the list:

--- a/drivers/crypto/dpaa_sec/dpaa_sec.c
+++ b/drivers/crypto/dpaa_sec/dpaa_sec.c
@@ -510,6 +510,7 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                         break;
                 default:
                         DPAA_SEC_ERR("unsupported auth alg %u", 
ses->auth_alg);
+                       /* this path will return 0 */
                 }
                 break;
         case DPAA_SEC_AEAD:
@@ -2308,7 +2309,7 @@ dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, 
dpaa_sec_session *sess)
         ret = dpaa_sec_prep_cdb(sess);
         if (ret) {
                 DPAA_SEC_ERR("Unable to prepare sec cdb");
-               return -1;
+               return -1; /* Why not return ret ? */
         }
         if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
                 ret = rte_dpaa_portal_init((void *)0);
@@ -2826,7 +2827,7 @@ dpaa_sec_set_ipsec_session(__rte_unused struct 
rte_cryptodev *dev,
                         }
                 }
         } else
-               goto out;
+               goto out; /* set ret before goto */
         rte_spinlock_lock(&internals->lock);
         for (i = 0; i < MAX_DPAA_CORES; i++) {
                 session->inq[i] = dpaa_sec_attach_rxq(internals);
@@ -2843,7 +2844,7 @@ dpaa_sec_set_ipsec_session(__rte_unused struct 
rte_cryptodev *dev,
         rte_free(session->auth_key.data);
         rte_free(session->cipher_key.data);
         memset(session, 0, sizeof(dpaa_sec_session));
-       return -1;
+       return -1; /* return ret ? */
  }

  static int
@@ -2992,7 +2993,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
         rte_free(session->auth_key.data);
         rte_free(session->cipher_key.data);
         memset(session, 0, sizeof(dpaa_sec_session));
-       return -1;
+       return -1; /* still returning generic -1 */
  }

  static int

-- 

Lukasz Wojciechowski
Principal Software Engineer

Samsung R&D Institute Poland
Samsung Electronics
Office +48 22 377 88 25
l.wojciechow@partner.samsung.com


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: improve error handling
  2020-05-05  1:17   ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Lukasz Wojciechowski
@ 2020-05-05 13:47     ` Akhil Goyal
  0 siblings, 0 replies; 11+ messages in thread
From: Akhil Goyal @ 2020-05-05 13:47 UTC (permalink / raw)
  To: Lukasz Wojciechowski, dev; +Cc: Hemant Agrawal

Hi Lukasz,
> 
> Hi Akhil,
> 
> There are still few places, where returned error code is not set.
> Maybe you can add those places to your patch?

Thanks for the review. I will surely look into it.


> 
> Here's the list:
> 
> --- a/drivers/crypto/dpaa_sec/dpaa_sec.c
> +++ b/drivers/crypto/dpaa_sec/dpaa_sec.c
> @@ -510,6 +510,7 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
>                          break;
>                  default:
>                          DPAA_SEC_ERR("unsupported auth alg %u",
> ses->auth_alg);
> +                       /* this path will return 0 */
>                  }
>                  break;
>          case DPAA_SEC_AEAD:
> @@ -2308,7 +2309,7 @@ dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp,
> dpaa_sec_session *sess)
>          ret = dpaa_sec_prep_cdb(sess);
>          if (ret) {
>                  DPAA_SEC_ERR("Unable to prepare sec cdb");
> -               return -1;
> +               return -1; /* Why not return ret ? */
>          }
>          if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
>                  ret = rte_dpaa_portal_init((void *)0);
> @@ -2826,7 +2827,7 @@ dpaa_sec_set_ipsec_session(__rte_unused struct
> rte_cryptodev *dev,
>                          }
>                  }
>          } else
> -               goto out;
> +               goto out; /* set ret before goto */
>          rte_spinlock_lock(&internals->lock);
>          for (i = 0; i < MAX_DPAA_CORES; i++) {
>                  session->inq[i] = dpaa_sec_attach_rxq(internals);
> @@ -2843,7 +2844,7 @@ dpaa_sec_set_ipsec_session(__rte_unused struct
> rte_cryptodev *dev,
>          rte_free(session->auth_key.data);
>          rte_free(session->cipher_key.data);
>          memset(session, 0, sizeof(dpaa_sec_session));
> -       return -1;
> +       return -1; /* return ret ? */
>   }
> 
>   static int
> @@ -2992,7 +2993,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev
> *dev,
>          rte_free(session->auth_key.data);
>          rte_free(session->cipher_key.data);
>          memset(session, 0, sizeof(dpaa_sec_session));
> -       return -1;
> +       return -1; /* still returning generic -1 */
>   }
> 
>   static int
> 
> --
> 
> Lukasz Wojciechowski
> Principal Software Engineer
> 
> Samsung R&D Institute Poland
> Samsung Electronics
> Office +48 22 377 88 25
> l.wojciechow@partner.samsung.com


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v3 1/2] crypto/dpaa2_sec: improve error handling
  2020-05-04 21:39 ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Akhil Goyal
  2020-05-04 21:39   ` [dpdk-dev] [PATCH v2 2/2] crypto/dpaa_sec: " Akhil Goyal
  2020-05-05  1:17   ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Lukasz Wojciechowski
@ 2020-05-09 22:22   ` Akhil Goyal
  2020-05-09 22:22     ` [dpdk-dev] [PATCH v3 2/2] crypto/dpaa_sec: " Akhil Goyal
  2020-05-11  6:13     ` [dpdk-dev] [PATCH v3 1/2] crypto/dpaa2_sec: " Hemant Agrawal (OSS)
  2 siblings, 2 replies; 11+ messages in thread
From: Akhil Goyal @ 2020-05-09 22:22 UTC (permalink / raw)
  To: dev; +Cc: hemant.agrawal, Akhil Goyal

The return values in cases of errors were not
specified properly. With this patch appropriate
error numbers are returned.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
Changes in v3: some return values were missed. It is now updated

 drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 120 +++++++++++---------
 1 file changed, 69 insertions(+), 51 deletions(-)

diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index 0919f3bf4..f2a1c302c 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -86,7 +86,7 @@ build_proto_compound_sg_fd(dpaa2_sec_session *sess,
 			RTE_CACHE_LINE_SIZE);
 	if (unlikely(!fle)) {
 		DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
 	DPAA2_SET_FLE_ADDR(fle, (size_t)op);
@@ -202,7 +202,7 @@ build_proto_compound_fd(dpaa2_sec_session *sess,
 	retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
 	if (retval) {
 		DPAA2_SEC_DP_ERR("Memory alloc failed");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_POOL_BUF_SIZE);
 	DPAA2_SET_FLE_ADDR(fle, (size_t)op);
@@ -315,7 +315,7 @@ build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
 			RTE_CACHE_LINE_SIZE);
 	if (unlikely(!fle)) {
 		DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
 	DPAA2_SET_FLE_ADDR(fle, (size_t)op);
@@ -463,7 +463,7 @@ build_authenc_gcm_fd(dpaa2_sec_session *sess,
 	retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
 	if (retval) {
 		DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_POOL_BUF_SIZE);
 	DPAA2_SET_FLE_ADDR(fle, (size_t)op);
@@ -604,7 +604,7 @@ build_authenc_sg_fd(dpaa2_sec_session *sess,
 			RTE_CACHE_LINE_SIZE);
 	if (unlikely(!fle)) {
 		DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
 	DPAA2_SET_FLE_ADDR(fle, (size_t)op);
@@ -755,7 +755,7 @@ build_authenc_fd(dpaa2_sec_session *sess,
 	retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
 	if (retval) {
 		DPAA2_SEC_ERR("Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_POOL_BUF_SIZE);
 	DPAA2_SET_FLE_ADDR(fle, (size_t)op);
@@ -885,7 +885,7 @@ static inline int build_auth_sg_fd(
 	    sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
 		if ((data_len & 7) || (data_offset & 7)) {
 			DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
-			return -1;
+			return -ENOTSUP;
 		}
 
 		data_len = data_len >> 3;
@@ -898,7 +898,7 @@ static inline int build_auth_sg_fd(
 			RTE_CACHE_LINE_SIZE);
 	if (unlikely(!fle)) {
 		DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs));
 	/* first FLE entry used to store mbuf and session ctxt */
@@ -1002,7 +1002,7 @@ build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
 	    sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
 		if ((data_len & 7) || (data_offset & 7)) {
 			DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
-			return -1;
+			return -ENOTSUP;
 		}
 
 		data_len = data_len >> 3;
@@ -1012,7 +1012,7 @@ build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
 	retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
 	if (retval) {
 		DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_POOL_BUF_SIZE);
 	/* TODO we are using the first FLE entry to store Mbuf.
@@ -1117,7 +1117,7 @@ build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
 		sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
 		if ((data_len & 7) || (data_offset & 7)) {
 			DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
-			return -1;
+			return -ENOTSUP;
 		}
 
 		data_len = data_len >> 3;
@@ -1135,7 +1135,7 @@ build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
 			RTE_CACHE_LINE_SIZE);
 	if (!fle) {
 		DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
 	/* first FLE entry used to store mbuf and session ctxt */
@@ -1250,7 +1250,7 @@ build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
 		sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
 		if ((data_len & 7) || (data_offset & 7)) {
 			DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
-			return -1;
+			return -ENOTSUP;
 		}
 
 		data_len = data_len >> 3;
@@ -1265,7 +1265,7 @@ build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
 	retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
 	if (retval) {
 		DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(fle, 0, FLE_POOL_BUF_SIZE);
 	/* TODO we are using the first FLE entry to store Mbuf.
@@ -1363,10 +1363,10 @@ build_sec_fd(struct rte_crypto_op *op,
 				op->sym->sec_session);
 #endif
 	else
-		return -1;
+		return -ENOTSUP;
 
 	if (!sess)
-		return -1;
+		return -EINVAL;
 
 	/* Any of the buffer is segmented*/
 	if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
@@ -1420,6 +1420,7 @@ build_sec_fd(struct rte_crypto_op *op,
 		case DPAA2_SEC_HASH_CIPHER:
 		default:
 			DPAA2_SEC_ERR("error: Unsupported session");
+			ret = -ENOTSUP;
 		}
 	}
 	return ret;
@@ -1770,7 +1771,7 @@ dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 			RTE_CACHE_LINE_SIZE);
 	if (!qp) {
 		DPAA2_SEC_ERR("malloc failed for rx/tx queues");
-		return -1;
+		return -ENOMEM;
 	}
 
 	qp->rx_vq.crypto_data = dev->data;
@@ -1780,13 +1781,13 @@ dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 		RTE_CACHE_LINE_SIZE);
 	if (!qp->rx_vq.q_storage) {
 		DPAA2_SEC_ERR("malloc failed for q_storage");
-		return -1;
+		return -ENOMEM;
 	}
 	memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
 
 	if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
 		DPAA2_SEC_ERR("Unable to allocate dequeue storage");
-		return -1;
+		return -ENOMEM;
 	}
 
 	dev->data->queue_pairs[qp_id] = qp;
@@ -1814,7 +1815,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 {
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo cipherdata;
-	int bufsize;
+	int bufsize, ret = 0;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 
@@ -1826,7 +1827,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -1839,7 +1840,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	if (session->cipher_key.data == NULL) {
 		DPAA2_SEC_ERR("No Memory for cipher key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = xform->cipher.key.length;
 
@@ -1916,15 +1917,18 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_CIPHER_NULL:
 		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			xform->cipher.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			xform->cipher.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Descriptor build failed");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -1936,12 +1940,12 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	for (i = 0; i < bufsize; i++)
 		DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
 #endif
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
@@ -1951,7 +1955,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 {
 	struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
 	struct alginfo authdata;
-	int bufsize;
+	int bufsize, ret = 0;
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 
@@ -1964,7 +1968,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -1976,7 +1980,7 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 	if (session->auth_key.data == NULL) {
 		DPAA2_SEC_ERR("Unable to allocate memory for auth key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->auth_key.length = xform->auth.key.length;
 
@@ -2082,15 +2086,18 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AUTH_AES_CBC_MAC:
 		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
 			      xform->auth.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      xform->auth.algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -2103,12 +2110,12 @@ dpaa2_sec_auth_init(struct rte_cryptodev *dev,
 				i, priv->flc_desc[DESC_INITFINAL].desc[i]);
 #endif
 
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->auth_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
@@ -2123,7 +2130,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	struct ctxt_priv *priv;
 	struct sec_flow_context *flc;
 	struct rte_crypto_aead_xform *aead_xform = &xform->aead;
-	int err;
+	int err, ret = 0;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2138,7 +2145,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -2149,7 +2156,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for aead key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	memcpy(session->aead_key.data, aead_xform->key.data,
 	       aead_xform->key.length);
@@ -2172,10 +2179,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AEAD_AES_CCM:
 		DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
 			      aead_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
 			      aead_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
@@ -2189,6 +2198,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 
 	if (err < 0) {
 		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+		ret = -EINVAL;
 		goto error_out;
 	}
 	if (priv->flc_desc[0].desc[1] & 1) {
@@ -2212,6 +2222,7 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 				session->digest_length);
 	if (bufsize < 0) {
 		DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+		ret = -EINVAL;
 		goto error_out;
 	}
 
@@ -2223,12 +2234,12 @@ dpaa2_sec_aead_init(struct rte_cryptodev *dev,
 		DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
 			    i, priv->flc_desc[0].desc[i]);
 #endif
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->aead_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 
@@ -2244,7 +2255,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	struct sec_flow_context *flc;
 	struct rte_crypto_cipher_xform *cipher_xform;
 	struct rte_crypto_auth_xform *auth_xform;
-	int err;
+	int err, ret = 0;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2272,7 +2283,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 			RTE_CACHE_LINE_SIZE);
 	if (priv == NULL) {
 		DPAA2_SEC_ERR("No Memory for priv CTXT");
-		return -1;
+		return -ENOMEM;
 	}
 
 	priv->fle_pool = dev_priv->fle_pool;
@@ -2283,7 +2294,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for cipher key");
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = cipher_xform->key.length;
 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
@@ -2292,7 +2303,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 		DPAA2_SEC_ERR("No Memory for auth key");
 		rte_free(session->cipher_key.data);
 		rte_free(priv);
-		return -1;
+		return -ENOMEM;
 	}
 	session->auth_key.length = auth_xform->key.length;
 	memcpy(session->cipher_key.data, cipher_xform->key.data,
@@ -2354,10 +2365,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
 		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      auth_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	cipherdata.key = (size_t)session->cipher_key.data;
@@ -2389,10 +2402,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
 		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      cipher_xform->algo);
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
@@ -2407,6 +2422,7 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 
 	if (err < 0) {
 		DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
+		ret = -EINVAL;
 		goto error_out;
 	}
 	if (priv->flc_desc[0].desc[2] & 1) {
@@ -2434,10 +2450,12 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 					      session->dir);
 		if (bufsize < 0) {
 			DPAA2_SEC_ERR("Crypto: Invalid buffer length");
+			ret = -EINVAL;
 			goto error_out;
 		}
 	} else {
 		DPAA2_SEC_ERR("Hash before cipher not supported");
+		ret = -ENOTSUP;
 		goto error_out;
 	}
 
@@ -2450,13 +2468,13 @@ dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
 			    i, priv->flc_desc[0].desc[i]);
 #endif
 
-	return 0;
+	return ret;
 
 error_out:
 	rte_free(session->cipher_key.data);
 	rte_free(session->auth_key.data);
 	rte_free(priv);
-	return -1;
+	return ret;
 }
 
 static int
@@ -2470,7 +2488,7 @@ dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
 
 	if (unlikely(sess == NULL)) {
 		DPAA2_SEC_ERR("Invalid session struct");
-		return -1;
+		return -EINVAL;
 	}
 
 	memset(session, 0, sizeof(dpaa2_sec_session));
@@ -2531,7 +2549,7 @@ dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 					       RTE_CACHE_LINE_SIZE);
 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for aead key");
-		return -1;
+		return -ENOMEM;
 	}
 	memcpy(session->aead_key.data, aead_xform->key.data,
 	       aead_xform->key.length);
@@ -2559,7 +2577,7 @@ dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 		default:
 			DPAA2_SEC_ERR("Crypto: Undefined GCM digest %d",
 				      session->digest_length);
-			return -1;
+			return -EINVAL;
 		}
 		aeaddata->algmode = OP_ALG_AAI_GCM;
 		session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
@@ -2578,7 +2596,7 @@ dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 		default:
 			DPAA2_SEC_ERR("Crypto: Undefined CCM digest %d",
 				      session->digest_length);
-			return -1;
+			return -EINVAL;
 		}
 		aeaddata->algmode = OP_ALG_AAI_CCM;
 		session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
@@ -2586,7 +2604,7 @@ dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
 			      aead_xform->algo);
-		return -1;
+		return -ENOTSUP;
 	}
 	session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
 				DIR_ENC : DIR_DEC;
@@ -2691,11 +2709,11 @@ dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
 		DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 	cipherdata->key = (size_t)session->cipher_key.data;
 	cipherdata->keylen = session->cipher_key.length;
@@ -2725,11 +2743,11 @@ dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
 		DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	return 0;
@@ -3212,7 +3230,7 @@ dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
 	rte_free(session->auth_key.data);
 	rte_free(session->cipher_key.data);
 	rte_free(priv);
-	return -1;
+	return -EINVAL;
 }
 
 static int
@@ -3764,7 +3782,7 @@ dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
 	if (!dpseci) {
 		DPAA2_SEC_ERR(
 			"Error in allocating the memory for dpsec object");
-		return -1;
+		return -ENOMEM;
 	}
 	dpseci->regs = rte_mcp_ptr_list[0];
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v3 2/2] crypto/dpaa_sec: improve error handling
  2020-05-09 22:22   ` [dpdk-dev] [PATCH v3 " Akhil Goyal
@ 2020-05-09 22:22     ` Akhil Goyal
  2020-05-11  6:14       ` Hemant Agrawal (OSS)
  2020-05-11  6:13     ` [dpdk-dev] [PATCH v3 1/2] crypto/dpaa2_sec: " Hemant Agrawal (OSS)
  1 sibling, 1 reply; 11+ messages in thread
From: Akhil Goyal @ 2020-05-09 22:22 UTC (permalink / raw)
  To: dev; +Cc: hemant.agrawal, Akhil Goyal

The return values in cases of errors were not
specified properly. With this patch appropriate
error numbers are returned.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
Changes in v3: some return values were missed. It is now updated

 drivers/crypto/dpaa_sec/dpaa_sec.c | 46 ++++++++++++++++--------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/drivers/crypto/dpaa_sec/dpaa_sec.c b/drivers/crypto/dpaa_sec/dpaa_sec.c
index 097ab8de9..25dcbd259 100644
--- a/drivers/crypto/dpaa_sec/dpaa_sec.c
+++ b/drivers/crypto/dpaa_sec/dpaa_sec.c
@@ -2047,7 +2047,7 @@ dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      xform->cipher.algo);
-		return -1;
+		return -ENOTSUP;
 	}
 	session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
 			DIR_ENC : DIR_DEC;
@@ -2114,7 +2114,7 @@ dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
 			      xform->auth.algo);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
@@ -2149,7 +2149,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 					       RTE_CACHE_LINE_SIZE);
 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
 		DPAA_SEC_ERR("No Memory for cipher key");
-		return -1;
+		return -ENOMEM;
 	}
 	session->cipher_key.length = cipher_xform->key.length;
 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
@@ -2195,7 +2195,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
 			      auth_xform->algo);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	session->cipher_alg = cipher_xform->algo;
@@ -2216,7 +2216,7 @@ dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      cipher_xform->algo);
-		return -1;
+		return -ENOTSUP;
 	}
 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
 				DIR_ENC : DIR_DEC;
@@ -2252,7 +2252,7 @@ dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
 		break;
 	default:
 		DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg);
-		return -ENOMEM;
+		return -ENOTSUP;
 	}
 
 	session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
@@ -2303,7 +2303,7 @@ dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess)
 	ret = dpaa_sec_prep_cdb(sess);
 	if (ret) {
 		DPAA_SEC_ERR("Unable to prepare sec cdb");
-		return -1;
+		return ret;
 	}
 	if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
 		ret = rte_dpaa_portal_init((void *)0);
@@ -2378,7 +2378,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 				ret = dpaa_sec_chain_init(dev, xform, session);
 		} else {
 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
-			return -EINVAL;
+			return -ENOTSUP;
 		}
 	/* Authenticate then Cipher */
 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
@@ -2394,7 +2394,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 				ret = dpaa_sec_chain_init(dev, xform, session);
 		} else {
 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
-			return -EINVAL;
+			return -ENOTSUP;
 		}
 
 	/* AEAD operation for AES-GCM kind of Algorithms */
@@ -2417,6 +2417,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 		if (session->inq[i] == NULL) {
 			DPAA_SEC_ERR("unable to attach sec queue");
 			rte_spinlock_unlock(&internals->lock);
+			ret = -EBUSY;
 			goto err1;
 		}
 	}
@@ -2426,7 +2427,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
 
 err1:
 	free_session_data(session);
-	return -EINVAL;
+	return ret;
 }
 
 static int
@@ -2506,7 +2507,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 					       RTE_CACHE_LINE_SIZE);
 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
 		DPAA_SEC_ERR("No Memory for aead key");
-		return -1;
+		return -ENOMEM;
 	}
 	memcpy(session->aead_key.data, aead_xform->key.data,
 	       aead_xform->key.length);
@@ -2529,7 +2530,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 		default:
 			DPAA_SEC_ERR("Crypto: Undefined GCM digest %d",
 				     session->digest_length);
-			return -1;
+			return -EINVAL;
 		}
 		if (session->dir == DIR_ENC) {
 			memcpy(session->encap_pdb.gcm.salt,
@@ -2544,7 +2545,7 @@ dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined AEAD specified %u",
 			      aead_xform->algo);
-		return -1;
+		return -ENOTSUP;
 	}
 	return 0;
 }
@@ -2641,11 +2642,11 @@ dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
 		DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Auth specified %u",
 			      session->auth_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	switch (session->cipher_alg) {
@@ -2678,11 +2679,11 @@ dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
 		DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	default:
 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 			      session->cipher_alg);
-		return -1;
+		return -ENOTSUP;
 	}
 
 	return 0;
@@ -2857,6 +2858,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 	dpaa_sec_session *session = (dpaa_sec_session *)sess;
 	struct dpaa_sec_dev_private *dev_priv = dev->data->dev_private;
 	uint32_t i;
+	int ret;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2896,7 +2898,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 		default:
 			DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
 				      session->cipher_alg);
-			return -1;
+			return -EINVAL;
 		}
 
 		session->cipher_key.data = rte_zmalloc(NULL,
@@ -2925,6 +2927,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 		    pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_12) {
 			DPAA_SEC_ERR(
 				"PDCP Seq Num size should be 5/12 bits for cmode");
+			ret = -EINVAL;
 			goto out;
 		}
 	}
@@ -2947,7 +2950,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 			DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
 				      session->auth_alg);
 			rte_free(session->cipher_key.data);
-			return -1;
+			return -EINVAL;
 		}
 		session->auth_key.data = rte_zmalloc(NULL,
 						     auth_xform->key.length,
@@ -2982,6 +2985,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 		if (session->inq[i] == NULL) {
 			DPAA_SEC_ERR("unable to attach sec queue");
 			rte_spinlock_unlock(&dev_priv->lock);
+			ret = -EBUSY;
 			goto out;
 		}
 	}
@@ -2991,7 +2995,7 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
 	rte_free(session->auth_key.data);
 	rte_free(session->cipher_key.data);
 	memset(session, 0, sizeof(dpaa_sec_session));
-	return -1;
+	return ret;
 }
 
 static int
@@ -3242,7 +3246,7 @@ dpaa_sec_eventq_attach(const struct rte_cryptodev *dev,
 		break;
 	case RTE_SCHED_TYPE_ORDERED:
 		DPAA_SEC_ERR("Ordered queue schedule type is not supported\n");
-		return -1;
+		return -ENOTSUP;
 	default:
 		opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK;
 		qp->outq.cb.dqrr_dpdk_cb = dpaa_sec_process_parallel_event;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/2] crypto/dpaa2_sec: improve error handling
  2020-05-09 22:22   ` [dpdk-dev] [PATCH v3 " Akhil Goyal
  2020-05-09 22:22     ` [dpdk-dev] [PATCH v3 2/2] crypto/dpaa_sec: " Akhil Goyal
@ 2020-05-11  6:13     ` Hemant Agrawal (OSS)
  2020-05-11  7:59       ` Akhil Goyal
  1 sibling, 1 reply; 11+ messages in thread
From: Hemant Agrawal (OSS) @ 2020-05-11  6:13 UTC (permalink / raw)
  To: Akhil Goyal, dev

Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v3 2/2] crypto/dpaa_sec: improve error handling
  2020-05-09 22:22     ` [dpdk-dev] [PATCH v3 2/2] crypto/dpaa_sec: " Akhil Goyal
@ 2020-05-11  6:14       ` Hemant Agrawal (OSS)
  0 siblings, 0 replies; 11+ messages in thread
From: Hemant Agrawal (OSS) @ 2020-05-11  6:14 UTC (permalink / raw)
  To: Akhil Goyal, dev

Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/2] crypto/dpaa2_sec: improve error handling
  2020-05-11  6:13     ` [dpdk-dev] [PATCH v3 1/2] crypto/dpaa2_sec: " Hemant Agrawal (OSS)
@ 2020-05-11  7:59       ` Akhil Goyal
  0 siblings, 0 replies; 11+ messages in thread
From: Akhil Goyal @ 2020-05-11  7:59 UTC (permalink / raw)
  To: Hemant Agrawal (OSS), dev



> -----Original Message-----
> From: Hemant Agrawal (OSS) <hemant.agrawal@oss.nxp.com>
> Sent: Monday, May 11, 2020 11:44 AM
> To: Akhil Goyal <akhil.goyal@nxp.com>; dev@dpdk.org
> Subject: RE: [PATCH v3 1/2] crypto/dpaa2_sec: improve error handling
> 
> Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
Series Applied to dpdk-next-crypto

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-11  7:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04 20:39 [dpdk-dev] [PATCH 1/2] crypto/dpaa2_sec: improve error handling Akhil Goyal
2020-05-04 20:39 ` [dpdk-dev] [PATCH 2/2] crypto/dpaa_sec: " Akhil Goyal
2020-05-04 21:39 ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Akhil Goyal
2020-05-04 21:39   ` [dpdk-dev] [PATCH v2 2/2] crypto/dpaa_sec: " Akhil Goyal
2020-05-05  1:17   ` [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: " Lukasz Wojciechowski
2020-05-05 13:47     ` Akhil Goyal
2020-05-09 22:22   ` [dpdk-dev] [PATCH v3 " Akhil Goyal
2020-05-09 22:22     ` [dpdk-dev] [PATCH v3 2/2] crypto/dpaa_sec: " Akhil Goyal
2020-05-11  6:14       ` Hemant Agrawal (OSS)
2020-05-11  6:13     ` [dpdk-dev] [PATCH v3 1/2] crypto/dpaa2_sec: " Hemant Agrawal (OSS)
2020-05-11  7:59       ` Akhil Goyal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).