[2/2] crypto/dpaa2_sec: fix if check on memory allocation

Message ID 1611562534-6699-2-git-send-email-g.singh@nxp.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series [1/2] test/ipsec: fix return values |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance fail Performance Testing issues
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-testing warning Testing issues

Commit Message

Gagandeep Singh Jan. 25, 2021, 8:15 a.m. UTC
  When key length is 0, zmalloc will return NULL pointor
and in that case it should not return NOMEM.
So in this patch, adding a check on key length.

Fixes: 8d1f3a5d751b ("crypto/dpaa2_sec: support crypto operation")
Cc: akhil.goyal@nxp.com
---
 drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Akhil Goyal Jan. 27, 2021, 7:53 p.m. UTC | #1
> When key length is 0, zmalloc will return NULL pointor
> and in that case it should not return NOMEM.
> So in this patch, adding a check on key length.
> 
> Fixes: 8d1f3a5d751b ("crypto/dpaa2_sec: support crypto operation")
> Cc: akhil.goyal@nxp.com
> ---
Signed-off missing. Will add it while merging in crypto tree.

Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
  

Patch

diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index cab79db..05b194c 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -1842,7 +1842,7 @@  dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
 	session->ctxt_type = DPAA2_SEC_CIPHER;
 	session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
 			RTE_CACHE_LINE_SIZE);
-	if (session->cipher_key.data == NULL) {
+	if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
 		DPAA2_SEC_ERR("No Memory for cipher key");
 		rte_free(priv);
 		return -ENOMEM;