From: Cristian Stoica <cristian.sto...@freescale.com> The single exit point works for these reasons: - session is zeroed in when allocated and kfree is a non-op for null pointers - deinit functions continue only if their init counterparts succeded
cryptodev_hash_deinit is necessary in cases of failed allocations of ses_new->pages or ses_new->sg Signed-off-by: Cristian Stoica <cristian.sto...@freescale.com> Signed-off-by: Horia Geanta <horia.gea...@freescale.com> --- ioctl.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ioctl.c b/ioctl.c index a8500ef..0ee447a 100644 --- a/ioctl.c +++ b/ioctl.c @@ -227,25 +227,25 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop) if (alg_name) { ret = cryptodev_get_cipher_keylen(&keylen, sop, aead); if (unlikely(ret < 0)) - goto error_cipher; + goto error_init; key = kmalloc(keylen, GFP_KERNEL); ses_new->key = key; if (unlikely(!key)) { ret = -ENOMEM; - goto error_cipher; + goto error_init; } ret = cryptodev_get_cipher_key(key, sop, aead); if (unlikely(ret < 0)) - goto error_cipher; + goto error_init; ret = cryptodev_cipher_init(&ses_new->cdata, alg_name, key, keylen, stream, aead); if (ret < 0) { dprintk(1, KERN_DEBUG, "Failed to load cipher %s\n", alg_name); ret = -EINVAL; - goto error_cipher; + goto error_init; } } @@ -255,13 +255,13 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop) "Setting key failed for %s-%zu.\n", hash_name, (size_t)sop->mackeylen*8); ret = -EINVAL; - goto error_hash; + goto error_init; } if (sop->mackey && unlikely(copy_from_user(mackey, sop->mackey, sop->mackeylen))) { ret = -EFAULT; - goto error_hash; + goto error_init; } ret = cryptodev_hash_init(&ses_new->hdata, hash_name, hmac_mode, @@ -269,7 +269,7 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop) if (ret != 0) { dprintk(1, KERN_DEBUG, "Failed to load hash for %s\n", hash_name); ret = -EINVAL; - goto error_hash; + goto error_init; } } @@ -287,7 +287,7 @@ crypto_create_session(struct fcrypt *fcr, struct session_op *sop) if (ses_new->sg == NULL || ses_new->pages == NULL) { dprintk(0, KERN_DEBUG, "Memory error\n"); ret = -ENOMEM; - goto error_hash; + goto error_init; } /* put the new session to the list */ @@ -314,11 +314,11 @@ restart: return 0; -error_hash: +error_init: + cryptodev_hash_deinit(&ses_new->hdata); cryptodev_cipher_deinit(&ses_new->cdata); kfree(ses_new->sg); kfree(ses_new->pages); -error_cipher: kfree(key); kfree(ses_new); -- 1.7.7.6 _______________________________________________ Cryptodev-linux-devel mailing list Cryptodev-linux-devel@gna.org https://mail.gna.org/listinfo/cryptodev-linux-devel