linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Herbert Xu" <herbert@gondor.apana.org.au>
To: Linus Walleij <linus.walleij@linaro.org>,
	Lionel Debieve <lionel.debieve@foss.st.com>,
	Li kunyu <kunyu@nfschina.com>,
	davem@davemloft.net, linux-arm-kernel@lists.infradead.org,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	mcoquelin.stm32@gmail.com
Subject: [v5 PATCH 3/7] crypto: stm32 - Simplify finup
Date: Sat, 04 Mar 2023 17:37:13 +0800	[thread overview]
Message-ID: <E1pYOKH-000GYy-Rv@formenos.hmeau.com> (raw)
In-Reply-To: ZAMQjOdi8GfqDUQI@gondor.apana.org.au

The current finup code is unnecessarily convoluted.  There is no
need to call update and final separately as update already does
all the necessary work on its own.

Simplify this by utilising the HASH_FLAGS_FINUP bit in rctx to
indicate only finup and use the HASH_FLAGS_FINAL bit instead to
signify processing common to both final and finup.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 drivers/crypto/stm32/stm32-hash.c |   34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
index 298cabd29e36..473809b26566 100644
--- a/drivers/crypto/stm32/stm32-hash.c
+++ b/drivers/crypto/stm32/stm32-hash.c
@@ -417,7 +417,7 @@ static int stm32_hash_update_cpu(struct stm32_hash_dev *hdev)
 
 	dev_dbg(hdev->dev, "%s flags %lx\n", __func__, rctx->flags);
 
-	final = (rctx->flags & HASH_FLAGS_FINUP);
+	final = rctx->flags & HASH_FLAGS_FINAL;
 
 	while ((rctx->total >= rctx->buflen) ||
 	       (rctx->bufcnt + rctx->total >= rctx->buflen)) {
@@ -761,6 +761,11 @@ static int stm32_hash_init(struct ahash_request *req)
 
 static int stm32_hash_update_req(struct stm32_hash_dev *hdev)
 {
+	struct stm32_hash_request_ctx *rctx = ahash_request_ctx(hdev->req);
+
+	if (!(rctx->flags & HASH_FLAGS_CPU))
+		return stm32_hash_dma_send(hdev);
+
 	return stm32_hash_update_cpu(hdev);
 }
 
@@ -768,17 +773,14 @@ static int stm32_hash_final_req(struct stm32_hash_dev *hdev)
 {
 	struct ahash_request *req = hdev->req;
 	struct stm32_hash_request_ctx *rctx = ahash_request_ctx(req);
-	int err;
 	int buflen = rctx->bufcnt;
 
-	rctx->bufcnt = 0;
+	if (rctx->flags & HASH_FLAGS_FINUP)
+		return stm32_hash_update_req(hdev);
 
-	if (!(rctx->flags & HASH_FLAGS_CPU))
-		err = stm32_hash_dma_send(hdev);
-	else
-		err = stm32_hash_xmit_cpu(hdev, rctx->buffer, buflen, 1);
+	rctx->bufcnt = 0;
 
-	return err;
+	return stm32_hash_xmit_cpu(hdev, rctx->buffer, buflen, 1);
 }
 
 static void stm32_hash_emptymsg_fallback(struct ahash_request *req)
@@ -1000,7 +1002,7 @@ static int stm32_hash_final(struct ahash_request *req)
 {
 	struct stm32_hash_request_ctx *rctx = ahash_request_ctx(req);
 
-	rctx->flags |= HASH_FLAGS_FINUP;
+	rctx->flags |= HASH_FLAGS_FINAL;
 
 	return stm32_hash_enqueue(req, HASH_OP_FINAL);
 }
@@ -1010,25 +1012,13 @@ static int stm32_hash_finup(struct ahash_request *req)
 	struct stm32_hash_request_ctx *rctx = ahash_request_ctx(req);
 	struct stm32_hash_ctx *ctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
 	struct stm32_hash_dev *hdev = stm32_hash_find_dev(ctx);
-	int err1, err2;
 
 	rctx->flags |= HASH_FLAGS_FINUP;
 
 	if (hdev->dma_lch && stm32_hash_dma_aligned_data(req))
 		rctx->flags &= ~HASH_FLAGS_CPU;
 
-	err1 = stm32_hash_update(req);
-
-	if (err1 == -EINPROGRESS || err1 == -EBUSY)
-		return err1;
-
-	/*
-	 * final() has to be always called to cleanup resources
-	 * even if update() failed, except EINPROGRESS
-	 */
-	err2 = stm32_hash_final(req);
-
-	return err1 ?: err2;
+	return stm32_hash_final(req);
 }
 
 static int stm32_hash_digest(struct ahash_request *req)

  parent reply	other threads:[~2023-03-04  9:37 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 21:50 [PATCH] stm32: stm32-hash: Add kmalloc_array allocation check Li kunyu
2023-02-23  6:00 ` Herbert Xu
2023-02-24 23:14   ` Li kunyu
2023-02-23  9:33     ` Herbert Xu
2023-02-23  9:52       ` Linus Walleij
2023-02-23 10:10         ` [PATCH] crypto: stm32 - Save and restore between each request Herbert Xu
2023-02-24  5:51           ` [v2 PATCH] " Herbert Xu
2023-02-25  0:01             ` Linus Walleij
2023-02-25  2:26               ` Li kunyu
2023-02-25 23:15               ` Linus Walleij
2023-02-27 10:39             ` [v3 " Herbert Xu
2023-02-27 21:17               ` Linus Walleij
2023-02-27 21:28                 ` Linus Walleij
2023-02-28  8:58                   ` Herbert Xu
2023-02-28  9:12                 ` Herbert Xu
2023-02-28  9:23                   ` Herbert Xu
2023-02-28  9:48                     ` [v4 " Herbert Xu
2023-02-28 20:50                       ` Linus Walleij
2023-03-01  1:30                         ` Herbert Xu
2023-03-01  1:36                         ` Herbert Xu
2023-03-01  1:46                           ` Herbert Xu
2023-03-01 12:22                           ` Linus Walleij
2023-03-02  1:16                             ` Herbert Xu
2023-03-02  6:04                             ` Herbert Xu
2023-03-04  9:34                               ` [v5 PATCH 0/7] " Herbert Xu
2023-03-04  9:37                                 ` [v5 PATCH 1/7] crypto: stm32 - Save 54 CSR registers Herbert Xu
2023-03-05 21:48                                   ` Linus Walleij
2023-03-04  9:37                                 ` [v5 PATCH 2/7] crypto: stm32 - Move polling into do_one_request Herbert Xu
2023-03-05 21:51                                   ` Linus Walleij
2023-03-04  9:37                                 ` Herbert Xu [this message]
2023-03-05 22:08                                   ` [v5 PATCH 3/7] crypto: stm32 - Simplify finup Linus Walleij
2023-03-06  4:37                                     ` Herbert Xu
2023-03-04  9:37                                 ` [v5 PATCH 4/7] crypto: stm32 - Remove unused hdev->err field Herbert Xu
2023-03-05 22:11                                   ` Linus Walleij
2023-03-04  9:37                                 ` [v5 PATCH 5/7] crypto: stm32 - Move hash state into separate structure Herbert Xu
2023-03-04  9:37                                 ` [v5 PATCH 6/7] crypto: stm32 - Remove unused HASH_FLAGS_ERRORS Herbert Xu
2023-03-04  9:37                                 ` [v5 PATCH 7/7] crypto: stm32 - Save and restore between each request Herbert Xu
2023-03-06  4:41                                 ` [v6 PATCH 0/7] " Herbert Xu
2023-03-06  4:41                                   ` [v5 PATCH 1/7] crypto: stm32 - Save 54 CSR registers Herbert Xu
2023-03-06  4:42                                   ` [v5 PATCH 2/7] crypto: stm32 - Move polling into do_one_request Herbert Xu
2023-03-06  4:42                                   ` [v5 PATCH 3/7] crypto: stm32 - Simplify finup Herbert Xu
2023-03-06  8:28                                     ` Linus Walleij
2023-03-06  4:42                                   ` [v5 PATCH 4/7] crypto: stm32 - Remove unused hdev->err field Herbert Xu
2023-03-06  4:42                                   ` [v5 PATCH 5/7] crypto: stm32 - Move hash state into separate structure Herbert Xu
2023-03-06  9:59                                     ` Linus Walleij
2023-03-06  4:42                                   ` [v5 PATCH 6/7] crypto: stm32 - Remove unused HASH_FLAGS_ERRORS Herbert Xu
2023-03-06 10:01                                     ` Linus Walleij
2023-03-06  4:42                                   ` [v5 PATCH 7/7] crypto: stm32 - Save and restore between each request Herbert Xu
2023-03-06 10:08                                     ` Linus Walleij
2023-03-07 10:10                                       ` Herbert Xu
2023-03-07 15:31                                         ` Linus Walleij
2023-03-08  3:23                                           ` Herbert Xu
2023-03-08  3:40                                             ` Herbert Xu
2023-03-08  3:52                                               ` Herbert Xu
2023-03-08  9:05                                               ` Linus Walleij
2023-03-08  9:13                                                 ` Herbert Xu
2023-03-08 10:10                                                 ` Herbert Xu
2023-03-08 10:19                                                   ` Herbert Xu
2023-03-08 21:19                                                     ` Linus Walleij
2023-03-09  5:58                                                       ` Herbert Xu
2023-03-09  7:35                                                         ` Linus Walleij
2023-03-09  9:59                                                           ` Herbert Xu
2023-03-09 22:19                                                           ` David Laight
2023-03-10  8:07                                                             ` Linus Walleij
2023-03-07 13:55                                   ` [v6 PATCH 0/7] " lionel.debieve
2023-03-08  3:46                                     ` Herbert Xu
2023-03-11  9:08                                   ` [v7 PATCH 0/8] " Herbert Xu
2023-03-11  9:09                                     ` [v7 PATCH 1/8] crypto: stm32 - Save 54 CSR registers Herbert Xu
2023-03-11  9:09                                     ` [v7 PATCH 2/8] crypto: stm32 - Move polling into do_one_request Herbert Xu
2023-03-11  9:09                                     ` [v7 PATCH 3/8] crypto: stm32 - Simplify finup Herbert Xu
2023-03-11  9:09                                     ` [v7 PATCH 4/8] crypto: stm32 - Remove unused hdev->err field Herbert Xu
2023-03-11  9:09                                     ` [v7 PATCH 5/8] crypto: stm32 - Move hash state into separate structure Herbert Xu
2023-03-11  9:09                                     ` [v7 PATCH 6/8] crypto: stm32 - Remove unused HASH_FLAGS_ERRORS Herbert Xu
2023-03-11  9:09                                     ` [v7 PATCH 7/8] crypto: stm32 - Fix empty message processing Herbert Xu
2023-03-11 21:44                                       ` Linus Walleij
2023-03-11  9:09                                     ` [v7 PATCH 8/8] crypto: stm32 - Save and restore between each request Herbert Xu
2023-03-11 21:45                                       ` Linus Walleij
     [not found]                                       ` <e7cd1e8b-9ebc-ff6d-a8c4-1ccd11df6de1@foss.st.com>
2023-03-28  3:58                                         ` [Linux-stm32] " 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=E1pYOKH-000GYy-Rv@formenos.hmeau.com \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=kunyu@nfschina.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=lionel.debieve@foss.st.com \
    --cc=mcoquelin.stm32@gmail.com \
    /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).