crypto: atmel-ecc - simplify control flow in atmel_ecdh_set_secret
Subsystems (3)
PATCH 1/2 crypto: atmel-ecc - simplify control flow in atmel_ecdh_set_secret
Free the public key directly on I2C transaction failure and remove the free_public_key label to simplify the code.
Signed-off-by Thorsten Blum <[email protected]>
--- drivers/crypto/atmel-ecc.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/crypto/atmel-ecc.c +4 -7
@@ -107,17 +107,14 @@ static int atmel_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,atmel_i2c_init_genkey_cmd (cmd,DATA_SLOT_2 ); ret =atmel_i2c_send_receive (ctx->client, cmd); -if (ret) - goto free_public_key; +if (ret) { +kfree (public_key); + goto free_cmd; + }memcpy (public_key, &cmd->data[RSP_DATA_IDX ],ATMEL_ECC_PUBKEY_SIZE ); ctx->public_key = public_key; -kfree (cmd); -return 0 ; - -free_public_key: -kfree (public_key); free_cmd:kfree (cmd);return ret;
PATCH 2/2 crypto: atmel-ecc - drop redundant return variable
In atmel_ecdh_generate_public_key(), drop the redundant return variable and return -EINVAL and 0 directly.
Signed-off-by Thorsten Blum <[email protected]>
--- drivers/crypto/atmel-ecc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/crypto/atmel-ecc.c +2 -3
@@ -125,7 +125,6 @@ static int atmel_ecdh_generate_public_key(struct kpp_request *req)struct crypto_kpp *tfm =crypto_kpp_reqtfm (req);struct atmel_ecdh_ctx *ctx =kpp_tfm_ctx (tfm);size_t copied, nbytes; -int ret =0 ;if (ctx->do_fallback) {kpp_request_set_tfm (req, ctx->fallback);
@@ -143,9 +142,9 @@ static int atmel_ecdh_generate_public_key(struct kpp_request *req)sg_nents_for_len (req->dst, nbytes), ctx->public_key, nbytes);if (copied != nbytes) - ret = -EINVAL ; +return -EINVAL ; -return ret; +return 0 ; }static int atmel_ecdh_compute_shared_secret (struct kpp_request *req)
Herbert Xu
maintainerQuoted 7 lines · Thorsten Blum
Free the public key directly on I2C transaction failure and remove the
free_public_keylabel to simplify the code.Signed-off-by Thorsten Blum <[email protected]>--- drivers/crypto/atmel-ecc.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt