[1/2] crypto/dpaa2_sec: improve error handling

Message ID 20200504203915.9602-1-akhil.goyal@nxp.com (mailing list archive)
State Superseded, archived
Headers
Series [1/2] crypto/dpaa2_sec: improve error handling |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS

Commit Message

Akhil Goyal May 4, 2020, 8:39 p.m. UTC
  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(-)
  

Patch

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