@@ -356,6 +356,7 @@ static int seg6_hmac_init_algo(void)
356
356
struct crypto_shash * tfm ;
357
357
struct shash_desc * shash ;
358
358
int i , alg_count , cpu ;
359
+ int ret = - ENOMEM ;
359
360
360
361
alg_count = ARRAY_SIZE (hmac_algos );
361
362
@@ -366,12 +367,14 @@ static int seg6_hmac_init_algo(void)
366
367
algo = & hmac_algos [i ];
367
368
algo -> tfms = alloc_percpu (struct crypto_shash * );
368
369
if (!algo -> tfms )
369
- return - ENOMEM ;
370
+ goto error_out ;
370
371
371
372
for_each_possible_cpu (cpu ) {
372
373
tfm = crypto_alloc_shash (algo -> name , 0 , 0 );
373
- if (IS_ERR (tfm ))
374
- return PTR_ERR (tfm );
374
+ if (IS_ERR (tfm )) {
375
+ ret = PTR_ERR (tfm );
376
+ goto error_out ;
377
+ }
375
378
p_tfm = per_cpu_ptr (algo -> tfms , cpu );
376
379
* p_tfm = tfm ;
377
380
}
@@ -383,18 +386,22 @@ static int seg6_hmac_init_algo(void)
383
386
384
387
algo -> shashs = alloc_percpu (struct shash_desc * );
385
388
if (!algo -> shashs )
386
- return - ENOMEM ;
389
+ goto error_out ;
387
390
388
391
for_each_possible_cpu (cpu ) {
389
392
shash = kzalloc_node (shsize , GFP_KERNEL ,
390
393
cpu_to_node (cpu ));
391
394
if (!shash )
392
- return - ENOMEM ;
395
+ goto error_out ;
393
396
* per_cpu_ptr (algo -> shashs , cpu ) = shash ;
394
397
}
395
398
}
396
399
397
400
return 0 ;
401
+
402
+ error_out :
403
+ seg6_hmac_exit ();
404
+ return ret ;
398
405
}
399
406
400
407
int __init seg6_hmac_init (void )
@@ -412,22 +419,29 @@ int __net_init seg6_hmac_net_init(struct net *net)
412
419
void seg6_hmac_exit (void )
413
420
{
414
421
struct seg6_hmac_algo * algo = NULL ;
422
+ struct crypto_shash * tfm ;
423
+ struct shash_desc * shash ;
415
424
int i , alg_count , cpu ;
416
425
417
426
alg_count = ARRAY_SIZE (hmac_algos );
418
427
for (i = 0 ; i < alg_count ; i ++ ) {
419
428
algo = & hmac_algos [i ];
420
- for_each_possible_cpu (cpu ) {
421
- struct crypto_shash * tfm ;
422
- struct shash_desc * shash ;
423
429
424
- shash = * per_cpu_ptr (algo -> shashs , cpu );
425
- kfree (shash );
426
- tfm = * per_cpu_ptr (algo -> tfms , cpu );
427
- crypto_free_shash (tfm );
430
+ if (algo -> shashs ) {
431
+ for_each_possible_cpu (cpu ) {
432
+ shash = * per_cpu_ptr (algo -> shashs , cpu );
433
+ kfree (shash );
434
+ }
435
+ free_percpu (algo -> shashs );
436
+ }
437
+
438
+ if (algo -> tfms ) {
439
+ for_each_possible_cpu (cpu ) {
440
+ tfm = * per_cpu_ptr (algo -> tfms , cpu );
441
+ crypto_free_shash (tfm );
442
+ }
443
+ free_percpu (algo -> tfms );
428
444
}
429
- free_percpu (algo -> tfms );
430
- free_percpu (algo -> shashs );
431
445
}
432
446
}
433
447
EXPORT_SYMBOL (seg6_hmac_exit );
0 commit comments