@@ -3438,98 +3438,110 @@ static int test_acomp(struct crypto_acomp *tfm,
3438
3438
int ctcount , int dtcount )
3439
3439
{
3440
3440
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 ] = {};
3446
3445
struct crypto_wait wait ;
3446
+ struct acomp_req * req ;
3447
+ int ret = - ENOMEM ;
3448
+ unsigned int i ;
3447
3449
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 ;
3451
3456
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 ;
3456
3476
}
3457
3477
3458
3478
for (i = 0 ; i < ctcount ; i ++ ) {
3459
3479
unsigned int dlen = COMP_BUF_SIZE ;
3460
3480
int ilen = ctemplate [i ].inlen ;
3461
3481
void * input_vec ;
3482
+ int j ;
3462
3483
3463
3484
input_vec = kmemdup (ctemplate [i ].input , ilen , GFP_KERNEL );
3464
3485
if (!input_vec ) {
3465
3486
ret = - ENOMEM ;
3466
3487
goto out ;
3467
3488
}
3468
3489
3469
- memset (output , 0 , dlen );
3470
3490
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 );
3473
3492
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 );
3481
3496
}
3482
3497
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 ];
3487
3499
ret = crypto_wait_req (crypto_acomp_compress (req ), & wait );
3488
3500
if (ret ) {
3489
3501
pr_err ("alg: acomp: compression failed on test %d for %s: ret=%d\n" ,
3490
3502
i + 1 , algo , - ret );
3491
3503
kfree (input_vec );
3492
- acomp_request_free (req );
3493
3504
goto out ;
3494
3505
}
3495
3506
3496
3507
ilen = req -> dlen ;
3497
3508
dlen = COMP_BUF_SIZE ;
3498
- sg_init_one (& src , output , ilen );
3499
- sg_init_one (& dst , decomp_out , dlen );
3500
3509
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
+ }
3511
3525
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
+ }
3520
3533
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
+ }
3529
3542
}
3530
3543
3531
3544
kfree (input_vec );
3532
- acomp_request_free (req );
3533
3545
}
3534
3546
3535
3547
for (i = 0 ; i < dtcount ; i ++ ) {
@@ -3543,10 +3555,9 @@ static int test_acomp(struct crypto_acomp *tfm,
3543
3555
goto out ;
3544
3556
}
3545
3557
3546
- memset (output , 0 , dlen );
3547
3558
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 );
3550
3561
3551
3562
req = acomp_request_alloc (tfm );
3552
3563
if (!req ) {
@@ -3557,7 +3568,7 @@ static int test_acomp(struct crypto_acomp *tfm,
3557
3568
goto out ;
3558
3569
}
3559
3570
3560
- acomp_request_set_params (req , & src , & dst , ilen , dlen );
3571
+ acomp_request_set_params (req , src , dst , ilen , dlen );
3561
3572
acomp_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
3562
3573
crypto_req_done , & wait );
3563
3574
@@ -3579,10 +3590,10 @@ static int test_acomp(struct crypto_acomp *tfm,
3579
3590
goto out ;
3580
3591
}
3581
3592
3582
- if (memcmp (output , dtemplate [i ].output , req -> dlen )) {
3593
+ if (memcmp (output [ 0 ] , dtemplate [i ].output , req -> dlen )) {
3583
3594
pr_err ("alg: acomp: Decompression test %d failed for %s\n" ,
3584
3595
i + 1 , algo );
3585
- hexdump (output , req -> dlen );
3596
+ hexdump (output [ 0 ] , req -> dlen );
3586
3597
ret = - EINVAL ;
3587
3598
kfree (input_vec );
3588
3599
acomp_request_free (req );
@@ -3596,8 +3607,13 @@ static int test_acomp(struct crypto_acomp *tfm,
3596
3607
ret = 0 ;
3597
3608
3598
3609
out :
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 );
3601
3617
return ret ;
3602
3618
}
3603
3619
0 commit comments