From: marex@denx.de (Marek Vasut)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] crypto: Simplify the ahash_finup implementation
Date: Tue, 14 Jan 2014 18:33:49 +0100 [thread overview]
Message-ID: <1389720829-5963-4-git-send-email-marex@denx.de> (raw)
In-Reply-To: <1389720829-5963-1-git-send-email-marex@denx.de>
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 | 53 ++++++++++++++++++++---------------------------------
1 file changed, 20 insertions(+), 33 deletions(-)
diff --git a/crypto/ahash.c b/crypto/ahash.c
index 635cd49..561ebaf 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -350,20 +350,19 @@ static void ahash_def_finup_finish2(struct ahash_request *req, int err)
if (!err)
memcpy(priv->result, req->result,
crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
-
- kzfree(priv);
}
-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);
+ ahash_restore_req(req);
+
+ data = req->base.data;
+ req->base.complete(data, err);
}
static int ahash_def_finup_finish1(struct ahash_request *req, int err)
@@ -380,39 +379,27 @@ 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);
+
+ ahash_restore_req(req);
- 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));
}
--
1.8.5.2
next prev parent reply other threads:[~2014-01-14 17:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-14 17:33 [PATCH 0/3] crypto: Clean up ahash handling confusion Marek Vasut
2014-01-14 17:33 ` [PATCH 1/3] crypto: Fix the pointer voodoo in unaligned ahash Marek Vasut
2014-01-14 19:35 ` Tom Lendacky
2014-02-09 1:18 ` Herbert Xu
2014-02-09 6:15 ` Marek Vasut
2014-03-03 0:20 ` Marek Vasut
2014-01-14 17:33 ` [PATCH 2/3] crypto: Pull out the functions to save/restore request Marek Vasut
2014-01-14 17:33 ` Marek Vasut [this message]
2014-03-03 0:21 ` [PATCH 1/3 V2] crypto: Fix the pointer voodoo in unaligned ahash Marek Vasut
2014-03-03 0:21 ` [PATCH 2/3 V2] crypto: Pull out the functions to save/restore request Marek Vasut
2014-03-03 0:21 ` [PATCH 3/3 V2] crypto: Simplify the ahash_finup implementation Marek Vasut
2014-03-12 12:11 ` Herbert Xu
2014-03-13 1:21 ` Marek Vasut
2014-03-12 12:08 ` [PATCH 1/3 V2] crypto: Fix the pointer voodoo in unaligned ahash Herbert Xu
2014-03-13 1:20 ` Marek Vasut
2014-03-13 1:56 ` Herbert Xu
2014-03-13 4:01 ` Marek Vasut
2014-03-13 4:32 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1389720829-5963-4-git-send-email-marex@denx.de \
--to=marex@denx.de \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).