diff mbox series

crypto: tegra - do not transfer req when tegra_sha_init returns an error

Message ID 20241107125211.1679517-1-chenridong@huaweicloud.com
State New
Headers show
Series crypto: tegra - do not transfer req when tegra_sha_init returns an error | expand

Commit Message

Chen Ridong Nov. 7, 2024, 12:52 p.m. UTC
From: Chen Ridong <chenridong@huawei.com>

The tegra_sha_init function may return an error when memory is exhausted.
It should not transfer the request when tegra_sha_init returns an error.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 drivers/crypto/tegra/tegra-se-hash.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/crypto/tegra/tegra-se-hash.c b/drivers/crypto/tegra/tegra-se-hash.c
index 4d4bd727f498..7e888bf5f66a 100644
--- a/drivers/crypto/tegra/tegra-se-hash.c
+++ b/drivers/crypto/tegra/tegra-se-hash.c
@@ -612,6 +612,7 @@  static int tegra_sha_finup(struct ahash_request *req)
 
 static int tegra_sha_digest(struct ahash_request *req)
 {
+	int ret;
 	struct tegra_sha_reqctx *rctx = ahash_request_ctx(req);
 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
 	struct tegra_sha_ctx *ctx = crypto_ahash_ctx(tfm);
@@ -619,9 +620,11 @@  static int tegra_sha_digest(struct ahash_request *req)
 	if (ctx->fallback)
 		return tegra_sha_fallback_digest(req);
 
-	tegra_sha_init(req);
-	rctx->task |= SHA_UPDATE | SHA_FINAL;
+	ret = tegra_sha_init(req);
+	if (ret)
+		return ret;
 
+	rctx->task |= SHA_UPDATE | SHA_FINAL;
 	return crypto_transfer_hash_request_to_engine(ctx->se->engine, req);
 }