From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 944C0A04AE; Mon, 4 May 2020 23:00:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EEC9C1D53B; Mon, 4 May 2020 23:00:11 +0200 (CEST) Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by dpdk.org (Postfix) with ESMTP id 597261D52C for ; Mon, 4 May 2020 23:00:10 +0200 (CEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id D87B8200547; Mon, 4 May 2020 23:00:09 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 0AB51200542; Mon, 4 May 2020 23:00:08 +0200 (CEST) Received: from GDB1.ap.freescale.net (gdb1.ap.freescale.net [10.232.132.179]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id DEA7E40310; Tue, 5 May 2020 05:00:05 +0800 (SGT) From: Akhil Goyal To: dev@dpdk.org Cc: hemant.agrawal@nxp.com, Akhil Goyal Date: Tue, 5 May 2020 02:09:14 +0530 Message-Id: <20200504203915.9602-1-akhil.goyal@nxp.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH 1/2] crypto/dpaa2_sec: improve error handling X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The return values in cases of errors were not specified properly. With this patch appropriate error numbers are returned. Signed-off-by: Akhil Goyal --- 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