Commit 32e55d03 authored by Herbert Xu's avatar Herbert Xu

crypto: stm32 - Simplify finup

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.
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Tested-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 34f39da7
...@@ -417,7 +417,7 @@ static int stm32_hash_update_cpu(struct stm32_hash_dev *hdev) ...@@ -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); 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) || while ((rctx->total >= rctx->buflen) ||
(rctx->bufcnt + rctx->total >= rctx->buflen)) { (rctx->bufcnt + rctx->total >= rctx->buflen)) {
...@@ -761,6 +761,11 @@ static int stm32_hash_init(struct ahash_request *req) ...@@ -761,6 +761,11 @@ static int stm32_hash_init(struct ahash_request *req)
static int stm32_hash_update_req(struct stm32_hash_dev *hdev) 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); return stm32_hash_update_cpu(hdev);
} }
...@@ -768,17 +773,14 @@ static int stm32_hash_final_req(struct stm32_hash_dev *hdev) ...@@ -768,17 +773,14 @@ static int stm32_hash_final_req(struct stm32_hash_dev *hdev)
{ {
struct ahash_request *req = hdev->req; struct ahash_request *req = hdev->req;
struct stm32_hash_request_ctx *rctx = ahash_request_ctx(req); struct stm32_hash_request_ctx *rctx = ahash_request_ctx(req);
int err;
int buflen = rctx->bufcnt; 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)) rctx->bufcnt = 0;
err = stm32_hash_dma_send(hdev);
else
err = stm32_hash_xmit_cpu(hdev, rctx->buffer, buflen, 1);
return err; return stm32_hash_xmit_cpu(hdev, rctx->buffer, buflen, 1);
} }
static void stm32_hash_emptymsg_fallback(struct ahash_request *req) static void stm32_hash_emptymsg_fallback(struct ahash_request *req)
...@@ -1000,7 +1002,7 @@ static int stm32_hash_final(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); 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); return stm32_hash_enqueue(req, HASH_OP_FINAL);
} }
...@@ -1010,25 +1012,20 @@ static int stm32_hash_finup(struct ahash_request *req) ...@@ -1010,25 +1012,20 @@ static int stm32_hash_finup(struct ahash_request *req)
struct stm32_hash_request_ctx *rctx = ahash_request_ctx(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_ctx *ctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
struct stm32_hash_dev *hdev = stm32_hash_find_dev(ctx); struct stm32_hash_dev *hdev = stm32_hash_find_dev(ctx);
int err1, err2;
if (!req->nbytes)
goto out;
rctx->flags |= HASH_FLAGS_FINUP; rctx->flags |= HASH_FLAGS_FINUP;
rctx->total = req->nbytes;
rctx->sg = req->src;
rctx->offset = 0;
if (hdev->dma_lch && stm32_hash_dma_aligned_data(req)) if (hdev->dma_lch && stm32_hash_dma_aligned_data(req))
rctx->flags &= ~HASH_FLAGS_CPU; rctx->flags &= ~HASH_FLAGS_CPU;
err1 = stm32_hash_update(req); out:
return stm32_hash_final(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;
} }
static int stm32_hash_digest(struct ahash_request *req) static int stm32_hash_digest(struct ahash_request *req)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment