@@ -58,9 +58,6 @@ module_param(fuzz_iterations, uint, 0644);
58
58
MODULE_PARM_DESC (fuzz_iterations , "number of fuzz test iterations" );
59
59
#endif
60
60
61
- /* Multibuffer is unlimited. Set arbitrary limit for testing. */
62
- #define MAX_MB_MSGS 16
63
-
64
61
#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
65
62
66
63
/* a perfect nop */
@@ -3329,110 +3326,98 @@ static int test_acomp(struct crypto_acomp *tfm,
3329
3326
int ctcount , int dtcount )
3330
3327
{
3331
3328
const char * algo = crypto_tfm_alg_driver_name (crypto_acomp_tfm (tfm ));
3332
- struct scatterlist * src = NULL , * dst = NULL ;
3333
- struct acomp_req * reqs [MAX_MB_MSGS ] = {};
3334
- char * decomp_out [MAX_MB_MSGS ] = {};
3335
- char * output [MAX_MB_MSGS ] = {};
3336
- struct crypto_wait wait ;
3337
- struct acomp_req * req ;
3338
- int ret = - ENOMEM ;
3339
3329
unsigned int i ;
3330
+ char * output , * decomp_out ;
3331
+ int ret ;
3332
+ struct scatterlist src , dst ;
3333
+ struct acomp_req * req ;
3334
+ struct crypto_wait wait ;
3340
3335
3341
- src = kmalloc_array (MAX_MB_MSGS , sizeof (* src ), GFP_KERNEL );
3342
- if (!src )
3343
- goto out ;
3344
- dst = kmalloc_array (MAX_MB_MSGS , sizeof (* dst ), GFP_KERNEL );
3345
- if (!dst )
3346
- goto out ;
3347
-
3348
- for (i = 0 ; i < MAX_MB_MSGS ; i ++ ) {
3349
- reqs [i ] = acomp_request_alloc (tfm );
3350
- if (!reqs [i ])
3351
- goto out ;
3352
-
3353
- acomp_request_set_callback (reqs [i ],
3354
- CRYPTO_TFM_REQ_MAY_SLEEP |
3355
- CRYPTO_TFM_REQ_MAY_BACKLOG ,
3356
- crypto_req_done , & wait );
3357
- if (i )
3358
- acomp_request_chain (reqs [i ], reqs [0 ]);
3359
-
3360
- output [i ] = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3361
- if (!output [i ])
3362
- goto out ;
3336
+ output = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3337
+ if (!output )
3338
+ return - ENOMEM ;
3363
3339
3364
- decomp_out [i ] = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3365
- if (!decomp_out [i ])
3366
- goto out ;
3340
+ decomp_out = kmalloc (COMP_BUF_SIZE , GFP_KERNEL );
3341
+ if (!decomp_out ) {
3342
+ kfree (output );
3343
+ return - ENOMEM ;
3367
3344
}
3368
3345
3369
3346
for (i = 0 ; i < ctcount ; i ++ ) {
3370
3347
unsigned int dlen = COMP_BUF_SIZE ;
3371
3348
int ilen = ctemplate [i ].inlen ;
3372
3349
void * input_vec ;
3373
- int j ;
3374
3350
3375
3351
input_vec = kmemdup (ctemplate [i ].input , ilen , GFP_KERNEL );
3376
3352
if (!input_vec ) {
3377
3353
ret = - ENOMEM ;
3378
3354
goto out ;
3379
3355
}
3380
3356
3357
+ memset (output , 0 , dlen );
3381
3358
crypto_init_wait (& wait );
3382
- sg_init_one (src , input_vec , ilen );
3359
+ sg_init_one (& src , input_vec , ilen );
3360
+ sg_init_one (& dst , output , dlen );
3383
3361
3384
- for (j = 0 ; j < MAX_MB_MSGS ; j ++ ) {
3385
- sg_init_one (dst + j , output [j ], dlen );
3386
- acomp_request_set_params (reqs [j ], src , dst + j , ilen , dlen );
3362
+ req = acomp_request_alloc (tfm );
3363
+ if (!req ) {
3364
+ pr_err ("alg: acomp: request alloc failed for %s\n" ,
3365
+ algo );
3366
+ kfree (input_vec );
3367
+ ret = - ENOMEM ;
3368
+ goto out ;
3387
3369
}
3388
3370
3389
- req = reqs [0 ];
3371
+ acomp_request_set_params (req , & src , & dst , ilen , dlen );
3372
+ acomp_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
3373
+ crypto_req_done , & wait );
3374
+
3390
3375
ret = crypto_wait_req (crypto_acomp_compress (req ), & wait );
3391
3376
if (ret ) {
3392
3377
pr_err ("alg: acomp: compression failed on test %d for %s: ret=%d\n" ,
3393
3378
i + 1 , algo , - ret );
3394
3379
kfree (input_vec );
3380
+ acomp_request_free (req );
3395
3381
goto out ;
3396
3382
}
3397
3383
3398
3384
ilen = req -> dlen ;
3399
3385
dlen = COMP_BUF_SIZE ;
3386
+ sg_init_one (& src , output , ilen );
3387
+ sg_init_one (& dst , decomp_out , dlen );
3400
3388
crypto_init_wait (& wait );
3401
- for (j = 0 ; j < MAX_MB_MSGS ; j ++ ) {
3402
- sg_init_one (src + j , output [j ], ilen );
3403
- sg_init_one (dst + j , decomp_out [j ], dlen );
3404
- acomp_request_set_params (reqs [j ], src + j , dst + j , ilen , dlen );
3405
- }
3406
-
3407
- crypto_wait_req (crypto_acomp_decompress (req ), & wait );
3408
- for (j = 0 ; j < MAX_MB_MSGS ; j ++ ) {
3409
- ret = reqs [j ]-> base .err ;
3410
- if (ret ) {
3411
- pr_err ("alg: acomp: compression failed on test %d (%d) for %s: ret=%d\n" ,
3412
- i + 1 , j , algo , - ret );
3413
- kfree (input_vec );
3414
- goto out ;
3415
- }
3389
+ acomp_request_set_params (req , & src , & dst , ilen , dlen );
3416
3390
3417
- if (reqs [j ]-> dlen != ctemplate [i ].inlen ) {
3418
- pr_err ("alg: acomp: Compression test %d (%d) failed for %s: output len = %d\n" ,
3419
- i + 1 , j , algo , reqs [j ]-> dlen );
3420
- ret = - EINVAL ;
3421
- kfree (input_vec );
3422
- goto out ;
3423
- }
3391
+ ret = crypto_wait_req (crypto_acomp_decompress (req ), & wait );
3392
+ if (ret ) {
3393
+ pr_err ("alg: acomp: compression failed on test %d for %s: ret=%d\n" ,
3394
+ i + 1 , algo , - ret );
3395
+ kfree (input_vec );
3396
+ acomp_request_free (req );
3397
+ goto out ;
3398
+ }
3424
3399
3425
- if (memcmp (input_vec , decomp_out [j ], reqs [j ]-> dlen )) {
3426
- pr_err ("alg: acomp: Compression test %d (%d) failed for %s\n" ,
3427
- i + 1 , j , algo );
3428
- hexdump (output [j ], reqs [j ]-> dlen );
3429
- ret = - EINVAL ;
3430
- kfree (input_vec );
3431
- goto out ;
3432
- }
3400
+ if (req -> dlen != ctemplate [i ].inlen ) {
3401
+ pr_err ("alg: acomp: Compression test %d failed for %s: output len = %d\n" ,
3402
+ i + 1 , algo , req -> dlen );
3403
+ ret = - EINVAL ;
3404
+ kfree (input_vec );
3405
+ acomp_request_free (req );
3406
+ goto out ;
3407
+ }
3408
+
3409
+ if (memcmp (input_vec , decomp_out , req -> dlen )) {
3410
+ pr_err ("alg: acomp: Compression test %d failed for %s\n" ,
3411
+ i + 1 , algo );
3412
+ hexdump (output , req -> dlen );
3413
+ ret = - EINVAL ;
3414
+ kfree (input_vec );
3415
+ acomp_request_free (req );
3416
+ goto out ;
3433
3417
}
3434
3418
3435
3419
kfree (input_vec );
3420
+ acomp_request_free (req );
3436
3421
}
3437
3422
3438
3423
for (i = 0 ; i < dtcount ; i ++ ) {
@@ -3446,9 +3431,10 @@ static int test_acomp(struct crypto_acomp *tfm,
3446
3431
goto out ;
3447
3432
}
3448
3433
3434
+ memset (output , 0 , dlen );
3449
3435
crypto_init_wait (& wait );
3450
- sg_init_one (src , input_vec , ilen );
3451
- sg_init_one (dst , output [ 0 ] , dlen );
3436
+ sg_init_one (& src , input_vec , ilen );
3437
+ sg_init_one (& dst , output , dlen );
3452
3438
3453
3439
req = acomp_request_alloc (tfm );
3454
3440
if (!req ) {
@@ -3459,7 +3445,7 @@ static int test_acomp(struct crypto_acomp *tfm,
3459
3445
goto out ;
3460
3446
}
3461
3447
3462
- acomp_request_set_params (req , src , dst , ilen , dlen );
3448
+ acomp_request_set_params (req , & src , & dst , ilen , dlen );
3463
3449
acomp_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
3464
3450
crypto_req_done , & wait );
3465
3451
@@ -3481,10 +3467,10 @@ static int test_acomp(struct crypto_acomp *tfm,
3481
3467
goto out ;
3482
3468
}
3483
3469
3484
- if (memcmp (output [ 0 ] , dtemplate [i ].output , req -> dlen )) {
3470
+ if (memcmp (output , dtemplate [i ].output , req -> dlen )) {
3485
3471
pr_err ("alg: acomp: Decompression test %d failed for %s\n" ,
3486
3472
i + 1 , algo );
3487
- hexdump (output [ 0 ] , req -> dlen );
3473
+ hexdump (output , req -> dlen );
3488
3474
ret = - EINVAL ;
3489
3475
kfree (input_vec );
3490
3476
acomp_request_free (req );
@@ -3498,13 +3484,8 @@ static int test_acomp(struct crypto_acomp *tfm,
3498
3484
ret = 0 ;
3499
3485
3500
3486
out :
3501
- acomp_request_free (reqs [0 ]);
3502
- for (i = 0 ; i < MAX_MB_MSGS ; i ++ ) {
3503
- kfree (output [i ]);
3504
- kfree (decomp_out [i ]);
3505
- }
3506
- kfree (dst );
3507
- kfree (src );
3487
+ kfree (decomp_out );
3488
+ kfree (output );
3508
3489
return ret ;
3509
3490
}
3510
3491
0 commit comments