From 3926014666350f47d5d9b6a71ec61d193add084e Mon Sep 17 00:00:00 2001 From: Akhil R Date: Thu, 12 Oct 2023 12:00:50 +0530 Subject: [PATCH] crypto: tegra: Fix coverity and CERT C defects Fix the following coverity defects. ID 10181328, CID 687742 - Uninitialized variable ID 10181331 - Dead code ID 10181330, CID 687711 - Uninitialize variable ID 10181332 - Potential overflow ID 10181329 - Wrong data type Bug 3952896 Bug 3959323 Signed-off-by: Akhil R Change-Id: I62064ee9b0cef4ad78a1aa4980637fcd3df682d6 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2995805 Reviewed-by: Laxman Dewangan Reviewed-by: svcacv GVS: Gerrit_Virtual_Submit --- drivers/crypto/tegra/tegra-se-aes.c | 4 +--- drivers/crypto/tegra/tegra-se-hash.c | 6 +++--- drivers/crypto/tegra/tegra-se.h | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/tegra/tegra-se-aes.c b/drivers/crypto/tegra/tegra-se-aes.c index 6151fff6..f1476209 100644 --- a/drivers/crypto/tegra/tegra-se-aes.c +++ b/drivers/crypto/tegra/tegra-se-aes.c @@ -1216,8 +1216,6 @@ static int tegra_ccm_do_one_req(struct crypto_engine *engine, void *areq) goto out; } else { rctx->cryptlen = req->cryptlen - ctx->authsize; - if (ret) - goto out; /* CTR operation */ ret = tegra_ccm_do_ctr(ctx, rctx); @@ -1614,7 +1612,7 @@ static int tegra_cmac_do_one_req(struct crypto_engine *engine, void *areq) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct tegra_cmac_ctx *ctx = crypto_ahash_ctx(tfm); struct tegra_se *se = ctx->se; - int ret; + int ret = -EINVAL; if (rctx->task & SHA_UPDATE) { ret = tegra_cmac_do_update(req); diff --git a/drivers/crypto/tegra/tegra-se-hash.c b/drivers/crypto/tegra/tegra-se-hash.c index 07c3913e..fd7708bb 100644 --- a/drivers/crypto/tegra/tegra-se-hash.c +++ b/drivers/crypto/tegra/tegra-se-hash.c @@ -218,8 +218,8 @@ static int tegra_sha_prep_cmd(struct tegra_se *se, u32 *cpuvaddr, u64 msg_len, msg_left; int i = 0; - msg_len = rctx->total_len * 8; - msg_left = rctx->datbuf.size * 8; + msg_len = (u64)rctx->total_len * 8; + msg_left = (u64)rctx->datbuf.size * 8; /* * If IN_ADDR_HI_0.SZ > SHA_MSG_LEFT_[0-3] to the HASH engine, @@ -377,7 +377,7 @@ static int tegra_sha_do_one_req(struct crypto_engine *engine, void *areq) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct tegra_sha_ctx *ctx = crypto_ahash_ctx(tfm); struct tegra_se *se = ctx->se; - int ret; + int ret = -EINVAL; if (rctx->task & SHA_UPDATE) { ret = tegra_sha_do_update(req); diff --git a/drivers/crypto/tegra/tegra-se.h b/drivers/crypto/tegra/tegra-se.h index 6262852c..55a0cde9 100644 --- a/drivers/crypto/tegra/tegra-se.h +++ b/drivers/crypto/tegra/tegra-se.h @@ -440,9 +440,9 @@ struct tegra_se { struct device *dev; unsigned int opcode_addr; unsigned int stream_id; - unsigned int num_clks; unsigned int syncpt_id; void __iomem *base; + int num_clks; u32 owner; };