@@ -3438,98 +3438,110 @@ static int test_acomp(struct crypto_acomp *tfm,
34383438 int ctcount , int dtcount )
34393439{
34403440 const char * algo = crypto_tfm_alg_driver_name (crypto_acomp_tfm (tfm ));
3441- unsigned int i ;
3442- char * output , * decomp_out ;
3443- int ret ;
3444- struct scatterlist src , dst ;
3445- struct acomp_req * req ;
3441+ struct scatterlist * src = NULL , * dst = NULL ;
3442+ struct acomp_req * reqs [MAX_MB_MSGS ] = {};
3443+ char * decomp_out [MAX_MB_MSGS ] = {};
3444+ char * output [MAX_MB_MSGS ] = {};
34463445 struct crypto_wait wait ;
3446+ struct acomp_req * req ;
3447+ int ret = - ENOMEM ;
3448+ unsigned int i ;
34473449
3448- output = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3449- if (!output )
3450- return - ENOMEM ;
3450+ src = kmalloc_array (MAX_MB_MSGS , sizeof (* src ), GFP_KERNEL );
3451+ if (!src )
3452+ goto out ;
3453+ dst = kmalloc_array (MAX_MB_MSGS , sizeof (* dst ), GFP_KERNEL );
3454+ if (!dst )
3455+ goto out ;
34513456
3452- decomp_out = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3453- if (!decomp_out ) {
3454- kfree (output );
3455- return - ENOMEM ;
3457+ for (i = 0 ; i < MAX_MB_MSGS ; i ++ ) {
3458+ reqs [i ] = acomp_request_alloc (tfm );
3459+ if (!reqs [i ])
3460+ goto out ;
3461+
3462+ acomp_request_set_callback (reqs [i ],
3463+ CRYPTO_TFM_REQ_MAY_SLEEP |
3464+ CRYPTO_TFM_REQ_MAY_BACKLOG ,
3465+ crypto_req_done , & wait );
3466+ if (i )
3467+ acomp_request_chain (reqs [i ], reqs [0 ]);
3468+
3469+ output [i ] = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3470+ if (!output [i ])
3471+ goto out ;
3472+
3473+ decomp_out [i ] = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3474+ if (!decomp_out [i ])
3475+ goto out ;
34563476 }
34573477
34583478 for (i = 0 ; i < ctcount ; i ++ ) {
34593479 unsigned int dlen = COMP_BUF_SIZE ;
34603480 int ilen = ctemplate [i ].inlen ;
34613481 void * input_vec ;
3482+ int j ;
34623483
34633484 input_vec = kmemdup (ctemplate [i ].input , ilen , GFP_KERNEL );
34643485 if (!input_vec ) {
34653486 ret = - ENOMEM ;
34663487 goto out ;
34673488 }
34683489
3469- memset (output , 0 , dlen );
34703490 crypto_init_wait (& wait );
3471- sg_init_one (& src , input_vec , ilen );
3472- sg_init_one (& dst , output , dlen );
3491+ sg_init_one (src , input_vec , ilen );
34733492
3474- req = acomp_request_alloc (tfm );
3475- if (!req ) {
3476- pr_err ("alg: acomp: request alloc failed for %s\n" ,
3477- algo );
3478- kfree (input_vec );
3479- ret = - ENOMEM ;
3480- goto out ;
3493+ for (j = 0 ; j < MAX_MB_MSGS ; j ++ ) {
3494+ sg_init_one (dst + j , output [j ], dlen );
3495+ acomp_request_set_params (reqs [j ], src , dst + j , ilen , dlen );
34813496 }
34823497
3483- acomp_request_set_params (req , & src , & dst , ilen , dlen );
3484- acomp_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
3485- crypto_req_done , & wait );
3486-
3498+ req = reqs [0 ];
34873499 ret = crypto_wait_req (crypto_acomp_compress (req ), & wait );
34883500 if (ret ) {
34893501 pr_err ("alg: acomp: compression failed on test %d for %s: ret=%d\n" ,
34903502 i + 1 , algo , - ret );
34913503 kfree (input_vec );
3492- acomp_request_free (req );
34933504 goto out ;
34943505 }
34953506
34963507 ilen = req -> dlen ;
34973508 dlen = COMP_BUF_SIZE ;
3498- sg_init_one (& src , output , ilen );
3499- sg_init_one (& dst , decomp_out , dlen );
35003509 crypto_init_wait (& wait );
3501- acomp_request_set_params (req , & src , & dst , ilen , dlen );
3502-
3503- ret = crypto_wait_req (crypto_acomp_decompress (req ), & wait );
3504- if (ret ) {
3505- pr_err ("alg: acomp: compression failed on test %d for %s: ret=%d\n" ,
3506- i + 1 , algo , - ret );
3507- kfree (input_vec );
3508- acomp_request_free (req );
3509- goto out ;
3510- }
3510+ for (j = 0 ; j < MAX_MB_MSGS ; j ++ ) {
3511+ sg_init_one (src + j , output [j ], ilen );
3512+ sg_init_one (dst + j , decomp_out [j ], dlen );
3513+ acomp_request_set_params (reqs [j ], src + j , dst + j , ilen , dlen );
3514+ }
3515+
3516+ crypto_wait_req (crypto_acomp_decompress (req ), & wait );
3517+ for (j = 0 ; j < MAX_MB_MSGS ; j ++ ) {
3518+ ret = reqs [j ]-> base .err ;
3519+ if (ret ) {
3520+ pr_err ("alg: acomp: compression failed on test %d (%d) for %s: ret=%d\n" ,
3521+ i + 1 , j , algo , - ret );
3522+ kfree (input_vec );
3523+ goto out ;
3524+ }
35113525
3512- if (req -> dlen != ctemplate [i ].inlen ) {
3513- pr_err ("alg: acomp: Compression test %d failed for %s: output len = %d\n" ,
3514- i + 1 , algo , req -> dlen );
3515- ret = - EINVAL ;
3516- kfree (input_vec );
3517- acomp_request_free (req );
3518- goto out ;
3519- }
3526+ if (reqs [j ]-> dlen != ctemplate [i ].inlen ) {
3527+ pr_err ("alg: acomp: Compression test %d (%d) failed for %s: output len = %d\n" ,
3528+ i + 1 , j , algo , reqs [j ]-> dlen );
3529+ ret = - EINVAL ;
3530+ kfree (input_vec );
3531+ goto out ;
3532+ }
35203533
3521- if (memcmp (input_vec , decomp_out , req -> dlen )) {
3522- pr_err ("alg: acomp: Compression test %d failed for %s\n" ,
3523- i + 1 , algo );
3524- hexdump (output , req -> dlen );
3525- ret = - EINVAL ;
3526- kfree (input_vec );
3527- acomp_request_free ( req ) ;
3528- goto out ;
3534+ if (memcmp (input_vec , decomp_out [ j ], reqs [ j ] -> dlen )) {
3535+ pr_err ("alg: acomp: Compression test %d (%d) failed for %s\n" ,
3536+ i + 1 , j , algo );
3537+ hexdump (output [ j ], reqs [ j ] -> dlen );
3538+ ret = - EINVAL ;
3539+ kfree (input_vec );
3540+ goto out ;
3541+ }
35293542 }
35303543
35313544 kfree (input_vec );
3532- acomp_request_free (req );
35333545 }
35343546
35353547 for (i = 0 ; i < dtcount ; i ++ ) {
@@ -3543,10 +3555,9 @@ static int test_acomp(struct crypto_acomp *tfm,
35433555 goto out ;
35443556 }
35453557
3546- memset (output , 0 , dlen );
35473558 crypto_init_wait (& wait );
3548- sg_init_one (& src , input_vec , ilen );
3549- sg_init_one (& dst , output , dlen );
3559+ sg_init_one (src , input_vec , ilen );
3560+ sg_init_one (dst , output [ 0 ] , dlen );
35503561
35513562 req = acomp_request_alloc (tfm );
35523563 if (!req ) {
@@ -3557,7 +3568,7 @@ static int test_acomp(struct crypto_acomp *tfm,
35573568 goto out ;
35583569 }
35593570
3560- acomp_request_set_params (req , & src , & dst , ilen , dlen );
3571+ acomp_request_set_params (req , src , dst , ilen , dlen );
35613572 acomp_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
35623573 crypto_req_done , & wait );
35633574
@@ -3579,10 +3590,10 @@ static int test_acomp(struct crypto_acomp *tfm,
35793590 goto out ;
35803591 }
35813592
3582- if (memcmp (output , dtemplate [i ].output , req -> dlen )) {
3593+ if (memcmp (output [ 0 ] , dtemplate [i ].output , req -> dlen )) {
35833594 pr_err ("alg: acomp: Decompression test %d failed for %s\n" ,
35843595 i + 1 , algo );
3585- hexdump (output , req -> dlen );
3596+ hexdump (output [ 0 ] , req -> dlen );
35863597 ret = - EINVAL ;
35873598 kfree (input_vec );
35883599 acomp_request_free (req );
@@ -3596,8 +3607,13 @@ static int test_acomp(struct crypto_acomp *tfm,
35963607 ret = 0 ;
35973608
35983609out :
3599- kfree (decomp_out );
3600- kfree (output );
3610+ acomp_request_free (reqs [0 ]);
3611+ for (i = 0 ; i < MAX_MB_MSGS ; i ++ ) {
3612+ kfree (output [i ]);
3613+ kfree (decomp_out [i ]);
3614+ }
3615+ kfree (dst );
3616+ kfree (src );
36013617 return ret ;
36023618}
36033619
0 commit comments