[API-NEXT,v2,2/2] linux-gen: crypto: unify odp_crypto_session_create error path

Message ID 1502114410-25867-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • [API-NEXT,v2,1/2] api: crypto: clarify for odp_crypto_session_create
Related show

Commit Message

Github ODP bot Aug. 7, 2017, 2 p.m.
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Make sure that or error session is always returned as
ODP_CRYPTO_SESSION_INVALID.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 95 (lumag:crypto-session-create)
 ** https://github.com/Linaro/odp/pull/95
 ** Patch: https://github.com/Linaro/odp/pull/95.patch
 ** Base sha: 2394317ab247fa14b4e239aec512afee7eac4524
 ** Merge commit sha: bc2a40cc94ced5ba8ec7b86fbdef99958ed37009
 **/
 platform/linux-generic/odp_crypto.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index ca51bdf0..1f49261a 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -697,14 +697,11 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 	odp_crypto_generic_session_t *session;
 	int aes_gcm = 0;
 
-	/* Default to successful result */
-	*status = ODP_CRYPTO_SES_CREATE_ERR_NONE;
-
 	/* Allocate memory for this session */
 	session = alloc_session();
 	if (NULL == session) {
 		*status = ODP_CRYPTO_SES_CREATE_ERR_ENOMEM;
-		return -1;
+		goto err;
 	}
 
 	/* Copy parameters */
@@ -712,8 +709,8 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 
 	if (session->p.iv.length > MAX_IV_LEN) {
 		ODP_DBG("Maximum IV length exceeded\n");
-		free_session(session);
-		return -1;
+		*status = ODP_CRYPTO_SES_CREATE_ERR_INV_CIPHER;
+		goto err;
 	}
 
 	/* Copy IV data */
@@ -764,8 +761,7 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 	/* Check result */
 	if (rc) {
 		*status = ODP_CRYPTO_SES_CREATE_ERR_INV_CIPHER;
-		free_session(session);
-		return -1;
+		goto err;
 	}
 
 	aes_gcm = 0;
@@ -825,13 +821,20 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 	/* Check result */
 	if (rc) {
 		*status = ODP_CRYPTO_SES_CREATE_ERR_INV_AUTH;
-		free_session(session);
-		return -1;
+		goto err;
 	}
 
 	/* We're happy */
 	*session_out = (intptr_t)session;
+	*status = ODP_CRYPTO_SES_CREATE_ERR_NONE;
 	return 0;
+
+err:
+	/* error status should be set at this moment */
+	if (session != NULL)
+		free_session(session);
+	*session_out = ODP_CRYPTO_SESSION_INVALID;
+	return -1;
 }
 
 int odp_crypto_session_destroy(odp_crypto_session_t session)