diff mbox

[3/3,V2] crypto: Simplify the ahash_finup implementation

Message ID 1393806108-6374-3-git-send-email-marex@denx.de (mailing list archive)
State New, archived
Headers show

Commit Message

Marek Vasut March 3, 2014, 12:21 a.m. UTC
The ahash_def_finup() can make use of the request save/restore functions,
thus make it so. This simplifies the code a little and unifies the code
paths.

Note that the same remark about free()ing the req->priv applies here, the
req->priv can only be free()'d after the original request was restored.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
---
 crypto/ahash.c | 52 +++++++++++++++++++---------------------------------
 1 file changed, 19 insertions(+), 33 deletions(-)

V2: Same as with 1/3 V2, move the restoration and freeing of the private
    data right past memcpy() of the buffer.

Comments

Herbert Xu March 12, 2014, 12:11 p.m. UTC | #1
On Mon, Mar 03, 2014 at 01:21:48AM +0100, Marek Vasut wrote:
>
> -static void ahash_def_finup_done2(struct crypto_async_request *req, int err)
> +static void ahash_def_finup_done2(struct crypto_async_request *areq, int err)

Please keep the existing name to be consistent with the rest
of the crypto API code.  You should also use the same name in
your second patch for consistency.

Thanks,
Marek Vasut March 13, 2014, 1:21 a.m. UTC | #2
On Wednesday, March 12, 2014 at 01:11:01 PM, Herbert Xu wrote:
> On Mon, Mar 03, 2014 at 01:21:48AM +0100, Marek Vasut wrote:
> > -static void ahash_def_finup_done2(struct crypto_async_request *req, int
> > err) +static void ahash_def_finup_done2(struct crypto_async_request
> > *areq, int err)
> 
> Please keep the existing name to be consistent with the rest
> of the crypto API code.  You should also use the same name in
> your second patch for consistency.

Done.

Moreover, the original code this patch changes still has a bug I think. The 
invocation of areq->base.complete() is wrong in the original code here. I will 
post V3 of the patches where I explain the problem in detail.

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/crypto/ahash.c b/crypto/ahash.c
index 4faa50e..6f6d652 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -347,19 +347,18 @@  static void ahash_def_finup_finish2(struct ahash_request *req, int err)
 		memcpy(priv->result, req->result,
 		       crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
 
-	kzfree(priv);
+	ahash_restore_req(req);
 }
 
-static void ahash_def_finup_done2(struct crypto_async_request *req, int err)
+static void ahash_def_finup_done2(struct crypto_async_request *areq, int err)
 {
-	struct ahash_request *areq = req->data;
-	struct ahash_request_priv *priv = areq->priv;
-	crypto_completion_t complete = priv->complete;
-	void *data = priv->data;
+	struct ahash_request *req = areq->data;
+	struct crypto_async_request *data;
 
-	ahash_def_finup_finish2(areq, err);
+	ahash_def_finup_finish2(req, err);
 
-	complete(data, err);
+	data = req->base.data;
+	req->base.complete(data, err);
 }
 
 static int ahash_def_finup_finish1(struct ahash_request *req, int err)
@@ -376,41 +375,28 @@  out:
 	return err;
 }
 
-static void ahash_def_finup_done1(struct crypto_async_request *req, int err)
+static void ahash_def_finup_done1(struct crypto_async_request *areq, int err)
 {
-	struct ahash_request *areq = req->data;
-	struct ahash_request_priv *priv = areq->priv;
-	crypto_completion_t complete = priv->complete;
-	void *data = priv->data;
+	struct ahash_request *req = areq->data;
+	struct crypto_async_request *data;
 
-	err = ahash_def_finup_finish1(areq, err);
+	err = ahash_def_finup_finish1(req, err);
 
-	complete(data, err);
+	data = req->base.data;
+	req->base.complete(data, err);
 }
 
 static int ahash_def_finup(struct ahash_request *req)
 {
 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
-	unsigned long alignmask = crypto_ahash_alignmask(tfm);
-	unsigned int ds = crypto_ahash_digestsize(tfm);
-	struct ahash_request_priv *priv;
-
-	priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
-		       (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
-		       GFP_KERNEL : GFP_ATOMIC);
-	if (!priv)
-		return -ENOMEM;
-
-	priv->result = req->result;
-	priv->complete = req->base.complete;
-	priv->data = req->base.data;
+	int err;
 
-	req->result = PTR_ALIGN((u8 *)priv->ubuf, alignmask + 1);
-	req->base.complete = ahash_def_finup_done1;
-	req->base.data = req;
-	req->priv = priv;
+	err = ahash_save_req(req, ahash_def_finup_done1);
+	if (err)
+		return err;
 
-	return ahash_def_finup_finish1(req, tfm->update(req));
+	err = tfm->update(req);
+	return ahash_def_finup_finish1(req, err);
 }
 
 static int ahash_no_export(struct ahash_request *req, void *out)