@@ -248,6 +248,17 @@ static inline void mtk_aes_restore_sg(const struct mtk_aes_dma *dma)
248248 sg -> length += dma -> remainder ;
249249}
250250
251+ static inline int mtk_aes_complete (struct mtk_cryp * cryp ,
252+ struct mtk_aes_rec * aes ,
253+ int err )
254+ {
255+ aes -> flags &= ~AES_FLAGS_BUSY ;
256+ aes -> areq -> complete (aes -> areq , err );
257+ /* Handle new request */
258+ tasklet_schedule (& aes -> queue_task );
259+ return err ;
260+ }
261+
251262/*
252263 * Write descriptors for processing. This will configure the engine, load
253264 * the transform information and then start the packet processing.
@@ -352,7 +363,7 @@ static int mtk_aes_map(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
352363 ctx -> ct_dma = dma_map_single (cryp -> dev , & ctx -> ct , sizeof (ctx -> ct ),
353364 DMA_TO_DEVICE );
354365 if (unlikely (dma_mapping_error (cryp -> dev , ctx -> ct_dma )))
355- return - EINVAL ;
366+ goto exit ;
356367
357368 ctx -> tfm_dma = dma_map_single (cryp -> dev , & ctx -> tfm , sizeof (ctx -> tfm ),
358369 DMA_TO_DEVICE );
@@ -389,8 +400,8 @@ static int mtk_aes_map(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
389400tfm_map_err :
390401 dma_unmap_single (cryp -> dev , ctx -> ct_dma , sizeof (ctx -> ct ),
391402 DMA_TO_DEVICE );
392-
393- return - EINVAL ;
403+ exit :
404+ return mtk_aes_complete ( cryp , aes , - EINVAL ) ;
394405}
395406
396407/* Initialize transform information of CBC/ECB/CTR mode */
@@ -467,7 +478,7 @@ static int mtk_aes_dma(struct mtk_cryp *cryp, struct mtk_aes_rec *aes,
467478 padlen = mtk_aes_padlen (len );
468479
469480 if (len + padlen > AES_BUF_SIZE )
470- return - ENOMEM ;
481+ return mtk_aes_complete ( cryp , aes , - ENOMEM ) ;
471482
472483 if (!src_aligned ) {
473484 sg_copy_to_buffer (src , sg_nents (src ), aes -> buf , len );
@@ -527,14 +538,10 @@ static int mtk_aes_handle_queue(struct mtk_cryp *cryp, u8 id,
527538 return ctx -> start (cryp , aes );
528539}
529540
530- static int mtk_aes_complete (struct mtk_cryp * cryp , struct mtk_aes_rec * aes )
541+ static int mtk_aes_transfer_complete (struct mtk_cryp * cryp ,
542+ struct mtk_aes_rec * aes )
531543{
532- aes -> flags &= ~AES_FLAGS_BUSY ;
533- aes -> areq -> complete (aes -> areq , 0 );
534-
535- /* Handle new request */
536- tasklet_schedule (& aes -> queue_task );
537- return 0 ;
544+ return mtk_aes_complete (cryp , aes , 0 );
538545}
539546
540547static int mtk_aes_start (struct mtk_cryp * cryp , struct mtk_aes_rec * aes )
@@ -543,7 +550,7 @@ static int mtk_aes_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
543550 struct mtk_aes_reqctx * rctx = ablkcipher_request_ctx (req );
544551
545552 mtk_aes_set_mode (aes , rctx );
546- aes -> resume = mtk_aes_complete ;
553+ aes -> resume = mtk_aes_transfer_complete ;
547554
548555 return mtk_aes_dma (cryp , aes , req -> src , req -> dst , req -> nbytes );
549556}
@@ -568,7 +575,7 @@ static int mtk_aes_ctr_transfer(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
568575 /* Check for transfer completion. */
569576 cctx -> offset += aes -> total ;
570577 if (cctx -> offset >= req -> nbytes )
571- return mtk_aes_complete (cryp , aes );
578+ return mtk_aes_transfer_complete (cryp , aes );
572579
573580 /* Compute data length. */
574581 datalen = req -> nbytes - cctx -> offset ;
@@ -602,7 +609,6 @@ static int mtk_aes_ctr_transfer(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
602609 cctx -> iv [3 ] = cpu_to_be32 (ctr );
603610 crypto_inc ((u8 * )cctx -> iv , AES_BLOCK_SIZE );
604611 }
605- aes -> resume = mtk_aes_ctr_transfer ;
606612
607613 return mtk_aes_dma (cryp , aes , src , dst , datalen );
608614}
@@ -618,6 +624,7 @@ static int mtk_aes_ctr_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
618624 memcpy (cctx -> iv , req -> info , AES_BLOCK_SIZE );
619625 cctx -> offset = 0 ;
620626 aes -> total = 0 ;
627+ aes -> resume = mtk_aes_ctr_transfer ;
621628
622629 return mtk_aes_ctr_transfer (cryp , aes );
623630}
@@ -859,7 +866,7 @@ static int mtk_aes_gcm_dma(struct mtk_cryp *cryp, struct mtk_aes_rec *aes,
859866
860867 if (!src_aligned || !dst_aligned ) {
861868 if (aes -> total > AES_BUF_SIZE )
862- return - ENOMEM ;
869+ return mtk_aes_complete ( cryp , aes , - ENOMEM ) ;
863870
864871 if (!src_aligned ) {
865872 sg_copy_to_buffer (src , sg_nents (src ), aes -> buf , len );
@@ -905,7 +912,7 @@ static int mtk_aes_gcm_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
905912 aes -> total = len ;
906913 gctx -> textlen = req -> cryptlen - gctx -> authsize ;
907914 }
908- aes -> resume = mtk_aes_complete ;
915+ aes -> resume = mtk_aes_transfer_complete ;
909916
910917 return mtk_aes_gcm_dma (cryp , aes , req -> src , req -> dst , len );
911918}
0 commit comments