@@ -78,7 +78,7 @@ static struct blk_crypto_fallback_keyslot {
78
78
struct crypto_skcipher * tfms [BLK_ENCRYPTION_MODE_MAX ];
79
79
} * blk_crypto_keyslots ;
80
80
81
- static struct blk_crypto_profile blk_crypto_fallback_profile ;
81
+ static struct blk_crypto_profile * blk_crypto_fallback_profile ;
82
82
static struct workqueue_struct * blk_crypto_wq ;
83
83
static mempool_t * blk_crypto_bounce_page_pool ;
84
84
static struct bio_set crypto_bio_split ;
@@ -292,7 +292,7 @@ static bool blk_crypto_fallback_encrypt_bio(struct bio **bio_ptr)
292
292
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
293
293
* this bio's algorithm and key.
294
294
*/
295
- blk_st = blk_crypto_get_keyslot (& blk_crypto_fallback_profile ,
295
+ blk_st = blk_crypto_get_keyslot (blk_crypto_fallback_profile ,
296
296
bc -> bc_key , & slot );
297
297
if (blk_st != BLK_STS_OK ) {
298
298
src_bio -> bi_status = blk_st ;
@@ -395,7 +395,7 @@ static void blk_crypto_fallback_decrypt_bio(struct work_struct *work)
395
395
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
396
396
* this bio's algorithm and key.
397
397
*/
398
- blk_st = blk_crypto_get_keyslot (& blk_crypto_fallback_profile ,
398
+ blk_st = blk_crypto_get_keyslot (blk_crypto_fallback_profile ,
399
399
bc -> bc_key , & slot );
400
400
if (blk_st != BLK_STS_OK ) {
401
401
bio -> bi_status = blk_st ;
@@ -499,7 +499,7 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr)
499
499
return false;
500
500
}
501
501
502
- if (!__blk_crypto_cfg_supported (& blk_crypto_fallback_profile ,
502
+ if (!__blk_crypto_cfg_supported (blk_crypto_fallback_profile ,
503
503
& bc -> bc_key -> crypto_cfg )) {
504
504
bio -> bi_status = BLK_STS_NOTSUPP ;
505
505
return false;
@@ -526,15 +526,14 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr)
526
526
527
527
int blk_crypto_fallback_evict_key (const struct blk_crypto_key * key )
528
528
{
529
- return __blk_crypto_evict_key (& blk_crypto_fallback_profile , key );
529
+ return __blk_crypto_evict_key (blk_crypto_fallback_profile , key );
530
530
}
531
531
532
532
static bool blk_crypto_fallback_inited ;
533
533
static int blk_crypto_fallback_init (void )
534
534
{
535
535
int i ;
536
536
int err ;
537
- struct blk_crypto_profile * profile = & blk_crypto_fallback_profile ;
538
537
539
538
if (blk_crypto_fallback_inited )
540
539
return 0 ;
@@ -545,18 +544,27 @@ static int blk_crypto_fallback_init(void)
545
544
if (err )
546
545
goto out ;
547
546
548
- err = blk_crypto_profile_init (profile , blk_crypto_num_keyslots );
549
- if (err )
547
+ /* Dynamic allocation is needed because of lockdep_register_key(). */
548
+ blk_crypto_fallback_profile =
549
+ kzalloc (sizeof (* blk_crypto_fallback_profile ), GFP_KERNEL );
550
+ if (!blk_crypto_fallback_profile ) {
551
+ err = - ENOMEM ;
550
552
goto fail_free_bioset ;
553
+ }
554
+
555
+ err = blk_crypto_profile_init (blk_crypto_fallback_profile ,
556
+ blk_crypto_num_keyslots );
557
+ if (err )
558
+ goto fail_free_profile ;
551
559
err = - ENOMEM ;
552
560
553
- profile -> ll_ops = blk_crypto_fallback_ll_ops ;
554
- profile -> max_dun_bytes_supported = BLK_CRYPTO_MAX_IV_SIZE ;
561
+ blk_crypto_fallback_profile -> ll_ops = blk_crypto_fallback_ll_ops ;
562
+ blk_crypto_fallback_profile -> max_dun_bytes_supported = BLK_CRYPTO_MAX_IV_SIZE ;
555
563
556
564
/* All blk-crypto modes have a crypto API fallback. */
557
565
for (i = 0 ; i < BLK_ENCRYPTION_MODE_MAX ; i ++ )
558
- profile -> modes_supported [i ] = 0xFFFFFFFF ;
559
- profile -> modes_supported [BLK_ENCRYPTION_MODE_INVALID ] = 0 ;
566
+ blk_crypto_fallback_profile -> modes_supported [i ] = 0xFFFFFFFF ;
567
+ blk_crypto_fallback_profile -> modes_supported [BLK_ENCRYPTION_MODE_INVALID ] = 0 ;
560
568
561
569
blk_crypto_wq = alloc_workqueue ("blk_crypto_wq" ,
562
570
WQ_UNBOUND | WQ_HIGHPRI |
@@ -597,7 +605,9 @@ static int blk_crypto_fallback_init(void)
597
605
fail_free_wq :
598
606
destroy_workqueue (blk_crypto_wq );
599
607
fail_destroy_profile :
600
- blk_crypto_profile_destroy (profile );
608
+ blk_crypto_profile_destroy (blk_crypto_fallback_profile );
609
+ fail_free_profile :
610
+ kfree (blk_crypto_fallback_profile );
601
611
fail_free_bioset :
602
612
bioset_exit (& crypto_bio_split );
603
613
out :
0 commit comments