Skip to content

Commit 4797f6c

Browse files
ryderlee1110herbertx
authored andcommitted
crypto: mediatek - move mtk_aes_find_dev() to the right place
Move mtk_aes_find_dev() to right functions as nobody uses the 'cryp' under current flows. We can also avoid duplicate checks here and there in this way. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Vic Wu <vic.wu@mediatek.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 1bbbbcf commit 4797f6c

1 file changed

Lines changed: 14 additions & 25 deletions

File tree

‎drivers/crypto/mediatek/mtk-aes.c‎

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,19 @@ static int mtk_aes_setkey(struct crypto_ablkcipher *tfm,
651651

652652
static int mtk_aes_crypt(struct ablkcipher_request *req, u64 mode)
653653
{
654-
struct mtk_aes_base_ctx *ctx;
654+
struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
655+
struct mtk_aes_base_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
655656
struct mtk_aes_reqctx *rctx;
657+
struct mtk_cryp *cryp;
658+
659+
cryp = mtk_aes_find_dev(ctx);
660+
if (!cryp)
661+
return -ENODEV;
656662

657-
ctx = crypto_ablkcipher_ctx(crypto_ablkcipher_reqtfm(req));
658663
rctx = ablkcipher_request_ctx(req);
659664
rctx->mode = mode;
660665

661-
return mtk_aes_handle_queue(ctx->cryp, !(mode & AES_FLAGS_ENCRYPT),
666+
return mtk_aes_handle_queue(cryp, !(mode & AES_FLAGS_ENCRYPT),
662667
&req->base);
663668
}
664669

@@ -695,13 +700,6 @@ static int mtk_aes_ctr_decrypt(struct ablkcipher_request *req)
695700
static int mtk_aes_cra_init(struct crypto_tfm *tfm)
696701
{
697702
struct mtk_aes_ctx *ctx = crypto_tfm_ctx(tfm);
698-
struct mtk_cryp *cryp = NULL;
699-
700-
cryp = mtk_aes_find_dev(&ctx->base);
701-
if (!cryp) {
702-
pr_err("can't find crypto device\n");
703-
return -ENODEV;
704-
}
705703

706704
tfm->crt_ablkcipher.reqsize = sizeof(struct mtk_aes_reqctx);
707705
ctx->base.start = mtk_aes_start;
@@ -711,13 +709,6 @@ static int mtk_aes_cra_init(struct crypto_tfm *tfm)
711709
static int mtk_aes_ctr_cra_init(struct crypto_tfm *tfm)
712710
{
713711
struct mtk_aes_ctx *ctx = crypto_tfm_ctx(tfm);
714-
struct mtk_cryp *cryp = NULL;
715-
716-
cryp = mtk_aes_find_dev(&ctx->base);
717-
if (!cryp) {
718-
pr_err("can't find crypto device\n");
719-
return -ENODEV;
720-
}
721712

722713
tfm->crt_ablkcipher.reqsize = sizeof(struct mtk_aes_reqctx);
723714
ctx->base.start = mtk_aes_ctr_start;
@@ -923,14 +914,19 @@ static int mtk_aes_gcm_crypt(struct aead_request *req, u64 mode)
923914
struct mtk_aes_base_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
924915
struct mtk_aes_gcm_ctx *gctx = mtk_aes_gcm_ctx_cast(ctx);
925916
struct mtk_aes_reqctx *rctx = aead_request_ctx(req);
917+
struct mtk_cryp *cryp;
918+
919+
cryp = mtk_aes_find_dev(ctx);
920+
if (!cryp)
921+
return -ENODEV;
926922

927923
/* Empty messages are not supported yet */
928924
if (!gctx->textlen && !req->assoclen)
929925
return -EINVAL;
930926

931927
rctx->mode = AES_FLAGS_GCM | mode;
932928

933-
return mtk_aes_handle_queue(ctx->cryp, !!(mode & AES_FLAGS_ENCRYPT),
929+
return mtk_aes_handle_queue(cryp, !!(mode & AES_FLAGS_ENCRYPT),
934930
&req->base);
935931
}
936932

@@ -1046,13 +1042,6 @@ static int mtk_aes_gcm_decrypt(struct aead_request *req)
10461042
static int mtk_aes_gcm_init(struct crypto_aead *aead)
10471043
{
10481044
struct mtk_aes_gcm_ctx *ctx = crypto_aead_ctx(aead);
1049-
struct mtk_cryp *cryp = NULL;
1050-
1051-
cryp = mtk_aes_find_dev(&ctx->base);
1052-
if (!cryp) {
1053-
pr_err("can't find crypto device\n");
1054-
return -ENODEV;
1055-
}
10561045

10571046
ctx->ctr = crypto_alloc_skcipher("ctr(aes)", 0,
10581047
CRYPTO_ALG_ASYNC);

0 commit comments

Comments
 (0)