From: Akhil Goyal Date: Sat, 9 May 2020 22:22:58 +0000 (+0530) Subject: crypto/dpaa2_sec: improve error handling X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=94ae7667f723d743b42c1dddb7b9673c8986e285;p=dpdk.git crypto/dpaa2_sec: improve error handling The return values in cases of errors were not specified properly. With this patch appropriate error numbers are returned. Signed-off-by: Akhil Goyal Acked-by: Hemant Agrawal --- diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c index 0919f3bf47..f2a1c302cc 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 @@ out: 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];