DPDK patches and discussions
 help / color / mirror / Atom feed
From: Akhil Goyal <akhil.goyal@nxp.com>
To: dev@dpdk.org
Cc: hemant.agrawal@nxp.com, Akhil Goyal <akhil.goyal@nxp.com>
Subject: [dpdk-dev] [PATCH v2 1/2] crypto/dpaa2_sec: improve error handling
Date: Tue,  5 May 2020 03:09:20 +0530	[thread overview]
Message-ID: <20200504213921.15449-1-akhil.goyal@nxp.com> (raw)
In-Reply-To: <20200504203915.9602-1-akhil.goyal@nxp.com>

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


  parent reply	other threads:[~2020-05-04 22:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 20:39 [dpdk-dev] [PATCH " Akhil Goyal
2020-05-04 20:39 ` [dpdk-dev] [PATCH 2/2] crypto/dpaa_sec: " Akhil Goyal
2020-05-04 21:39 ` Akhil Goyal [this message]
2020-05-04 21:39   ` [dpdk-dev] [PATCH v2 " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200504213921.15449-1-akhil.goyal@nxp.com \
    --to=akhil.goyal@nxp.com \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).