Skip to contentSkip to conversation

crypto: atmel-ecc - simplify control flow in atmel_ecdh_set_secret

PATCH In review Thorsten Blum 2 participants 3 messages Jul 28 – Aug 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

---
 drivers/crypto/atmel-ecc.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/crypto/atmel-ecc.c +4 -7
index 21192a042fa2..f98782f0a2c6 100644
@@ -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;
#1 lore raw

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.

---
 drivers/crypto/atmel-ecc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/crypto/atmel-ecc.c +2 -3
index f98782f0a2c6..0c6ab5da9299 100644
@@ -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)
maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 7 lines · Thorsten Blum

Free the public key directly on I2C transaction failure and remove the free_public_key label to simplify the code.

---
 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