]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: aspeed/hash - Move sham_final call into sham_update
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 13 May 2025 06:03:57 +0000 (14:03 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 13 Jun 2025 09:26:15 +0000 (17:26 +0800)
The only time when sham_final needs to be called in sham_finup
is when the finup request fits into the partial block.  Move this
special handling into sham_update.

The comment about releaseing resources is non-sense.  The Crypto
API does not mandate the use of final so the user could always go
away after an update and never come back.  Therefore the driver
must not hold any resources after an update call.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/aspeed/aspeed-hace-hash.c

index 9f776ec8f5ec1208108212065d840a82d3dc527c..40363159489e3f6513d3aee7f91b267a87ef2cd6 100644 (file)
@@ -508,6 +508,20 @@ static int aspeed_ahash_do_one(struct crypto_engine *engine, void *areq)
        return aspeed_ahash_do_request(engine, areq);
 }
 
+static int aspeed_sham_final(struct ahash_request *req)
+{
+       struct aspeed_sham_reqctx *rctx = ahash_request_ctx(req);
+       struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+       struct aspeed_sham_ctx *tctx = crypto_ahash_ctx(tfm);
+       struct aspeed_hace_dev *hace_dev = tctx->hace_dev;
+
+       AHASH_DBG(hace_dev, "req->nbytes:%d, rctx->total:%d\n",
+                 req->nbytes, rctx->total);
+       rctx->op = SHA_OP_FINAL;
+
+       return aspeed_hace_hash_handle_queue(hace_dev, req);
+}
+
 static int aspeed_sham_update(struct ahash_request *req)
 {
        struct aspeed_sham_reqctx *rctx = ahash_request_ctx(req);
@@ -533,49 +547,25 @@ static int aspeed_sham_update(struct ahash_request *req)
                                         rctx->total, 0);
                rctx->bufcnt += rctx->total;
 
-               return 0;
+               return rctx->flags & SHA_FLAGS_FINUP ?
+                      aspeed_sham_final(req) : 0;
        }
 
        return aspeed_hace_hash_handle_queue(hace_dev, req);
 }
 
-static int aspeed_sham_final(struct ahash_request *req)
-{
-       struct aspeed_sham_reqctx *rctx = ahash_request_ctx(req);
-       struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
-       struct aspeed_sham_ctx *tctx = crypto_ahash_ctx(tfm);
-       struct aspeed_hace_dev *hace_dev = tctx->hace_dev;
-
-       AHASH_DBG(hace_dev, "req->nbytes:%d, rctx->total:%d\n",
-                 req->nbytes, rctx->total);
-       rctx->op = SHA_OP_FINAL;
-
-       return aspeed_hace_hash_handle_queue(hace_dev, req);
-}
-
 static int aspeed_sham_finup(struct ahash_request *req)
 {
        struct aspeed_sham_reqctx *rctx = ahash_request_ctx(req);
        struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
        struct aspeed_sham_ctx *tctx = crypto_ahash_ctx(tfm);
        struct aspeed_hace_dev *hace_dev = tctx->hace_dev;
-       int rc1, rc2;
 
        AHASH_DBG(hace_dev, "req->nbytes: %d\n", req->nbytes);
 
        rctx->flags |= SHA_FLAGS_FINUP;
 
-       rc1 = aspeed_sham_update(req);
-       if (rc1 == -EINPROGRESS || rc1 == -EBUSY)
-               return rc1;
-
-       /*
-        * final() has to be always called to cleanup resources
-        * even if update() failed, except EINPROGRESS
-        */
-       rc2 = aspeed_sham_final(req);
-
-       return rc1 ? : rc2;
+       return aspeed_sham_update(req);
 }
 
 static int aspeed_sham_init(struct ahash_request *req)