@@ -651,14 +651,19 @@ static int mtk_aes_setkey(struct crypto_ablkcipher *tfm,
651651
652652static 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)
695700static 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)
711709static 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)
10461042static 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