From: marex@denx.de (Marek Vasut)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3 V4] crypto: Pull out the functions to save/restore request
Date: Fri, 14 Mar 2014 02:37:05 +0100 [thread overview]
Message-ID: <1394761026-7292-2-git-send-email-marex@denx.de> (raw)
In-Reply-To: <1394761026-7292-1-git-send-email-marex@denx.de>
The functions to save original request within a newly adjusted request
and it's counterpart to restore the original request can be re-used by
more code in the crypto/ahash.c file. Pull these functions out from the
code so they're available.
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 | 107 +++++++++++++++++++++++++++++++++------------------------
1 file changed, 62 insertions(+), 45 deletions(-)
V2: Rebase on top of 1/3 V2 , no functional changes.
V3: Rebase on top of 1/3 V3 , no functional changes.
V4: Rebase on top of 1/3 V4 , no functional changes.
diff --git a/crypto/ahash.c b/crypto/ahash.c
index 4fdb4d3..fcc6077 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -190,55 +190,12 @@ static inline unsigned int ahash_align_buffer_size(unsigned len,
return len + (mask & ~(crypto_tfm_ctx_alignment() - 1));
}
-static void ahash_op_unaligned_finish(struct ahash_request *req, int err)
-{
- struct ahash_request_priv *priv = req->priv;
-
- if (err == -EINPROGRESS)
- return;
-
- if (!err)
- memcpy(priv->result, req->result,
- crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
-
- /* Restore the original crypto request. */
- req->result = priv->result;
- req->base.complete = priv->complete;
- req->base.data = priv->data;
- req->priv = NULL;
-
- /* Free the req->priv.priv from the ADJUSTED request. */
- kzfree(priv);
-}
-
-static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
-{
- struct ahash_request *areq = req->data;
-
- /*
- * Restore the original request, see ahash_op_unaligned() for what
- * goes where.
- *
- * The "struct ahash_request *req" here is in fact the "req.base"
- * from the ADJUSTED request from ahash_op_unaligned(), thus as it
- * is a pointer to self, it is also the ADJUSTED "req" .
- */
-
- /* First copy areq->result into areq->priv.result */
- ahash_op_unaligned_finish(areq, err);
-
- /* Complete the ORIGINAL request. */
- areq->base.complete(&areq->base, err);
-}
-
-static int ahash_op_unaligned(struct ahash_request *req,
- int (*op)(struct ahash_request *))
+static int ahash_save_req(struct ahash_request *req, crypto_completion_t cplt)
{
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;
- int err;
priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
(req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
@@ -281,10 +238,70 @@ static int ahash_op_unaligned(struct ahash_request *req,
*/
req->result = PTR_ALIGN((u8 *)priv->ubuf, alignmask + 1);
- req->base.complete = ahash_op_unaligned_done;
+ req->base.complete = cplt;
req->base.data = req;
req->priv = priv;
+ return 0;
+}
+
+static void ahash_restore_req(struct ahash_request *req)
+{
+ struct ahash_request_priv *priv = req->priv;
+
+ /* Restore the original crypto request. */
+ req->result = priv->result;
+ req->base.complete = priv->complete;
+ req->base.data = priv->data;
+ req->priv = NULL;
+
+ /* Free the req->priv.priv from the ADJUSTED request. */
+ kzfree(priv);
+}
+
+static void ahash_op_unaligned_finish(struct ahash_request *req, int err)
+{
+ struct ahash_request_priv *priv = req->priv;
+
+ if (err == -EINPROGRESS)
+ return;
+
+ if (!err)
+ memcpy(priv->result, req->result,
+ crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
+
+ ahash_restore_req(req);
+}
+
+static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
+{
+ struct ahash_request *areq = req->data;
+
+ /*
+ * Restore the original request, see ahash_op_unaligned() for what
+ * goes where.
+ *
+ * The "struct ahash_request *req" here is in fact the "req.base"
+ * from the ADJUSTED request from ahash_op_unaligned(), thus as it
+ * is a pointer to self, it is also the ADJUSTED "req" .
+ */
+
+ /* First copy req->result into req->priv.result */
+ ahash_op_unaligned_finish(areq, err);
+
+ /* Complete the ORIGINAL request. */
+ areq->base.complete(&areq->base, err);
+}
+
+static int ahash_op_unaligned(struct ahash_request *req,
+ int (*op)(struct ahash_request *))
+{
+ int err;
+
+ err = ahash_save_req(req, ahash_op_unaligned_done);
+ if (err)
+ return err;
+
err = op(req);
ahash_op_unaligned_finish(req, err);
--
1.8.5.2
next prev parent reply other threads:[~2014-03-14 1:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-14 1:37 [PATCH 1/3 V4] crypto: Fix the pointer voodoo in unaligned ahash Marek Vasut
2014-03-14 1:37 ` Marek Vasut [this message]
2014-03-14 1:37 ` [PATCH 3/3 V4] crypto: Simplify the ahash_finup implementation Marek Vasut
2014-03-21 14:40 ` [PATCH 1/3 V4] crypto: Fix the pointer voodoo in unaligned ahash Herbert Xu
2014-03-21 18:31 ` Marek Vasut
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=1394761026-7292-2-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).