@@ -84,36 +84,47 @@ static void crypto_destroy_instance(struct crypto_alg *alg)
8484 crypto_tmpl_put (tmpl );
8585}
8686
87- static void crypto_remove_spawns (struct list_head * spawns ,
88- struct list_head * list )
87+ static void crypto_remove_spawn (struct crypto_spawn * spawn ,
88+ struct list_head * list ,
89+ struct list_head * secondary_spawns )
8990{
90- struct crypto_spawn * spawn , * n ;
91+ struct crypto_instance * inst = spawn -> inst ;
92+ struct crypto_template * tmpl = inst -> tmpl ;
9193
92- list_for_each_entry_safe (spawn , n , spawns , list ) {
93- struct crypto_instance * inst = spawn -> inst ;
94- struct crypto_template * tmpl = inst -> tmpl ;
94+ list_del_init (& spawn -> list );
95+ spawn -> alg = NULL ;
9596
96- list_del_init ( & spawn -> list );
97- spawn -> alg = NULL ;
97+ if ( crypto_is_dead ( & inst -> alg ))
98+ return ;
9899
99- if (crypto_is_dead (& inst -> alg ))
100- continue ;
100+ inst -> alg .cra_flags |= CRYPTO_ALG_DEAD ;
101+ if (!tmpl || !crypto_tmpl_get (tmpl ))
102+ return ;
103+
104+ crypto_notify (CRYPTO_MSG_ALG_UNREGISTER , & inst -> alg );
105+ list_move (& inst -> alg .cra_list , list );
106+ hlist_del (& inst -> list );
107+ inst -> alg .cra_destroy = crypto_destroy_instance ;
108+
109+ list_splice (& inst -> alg .cra_users , secondary_spawns );
110+ }
111+
112+ static void crypto_remove_spawns (struct list_head * spawns ,
113+ struct list_head * list , u32 new_type )
114+ {
115+ struct crypto_spawn * spawn , * n ;
116+ LIST_HEAD (secondary_spawns );
101117
102- inst -> alg . cra_flags |= CRYPTO_ALG_DEAD ;
103- if (! tmpl || ! crypto_tmpl_get ( tmpl ) )
118+ list_for_each_entry_safe ( spawn , n , spawns , list ) {
119+ if (( spawn -> alg -> cra_flags ^ new_type ) & spawn -> mask )
104120 continue ;
105121
106- crypto_notify (CRYPTO_MSG_ALG_UNREGISTER , & inst -> alg );
107- list_move (& inst -> alg .cra_list , list );
108- hlist_del (& inst -> list );
109- inst -> alg .cra_destroy = crypto_destroy_instance ;
122+ crypto_remove_spawn (spawn , list , & secondary_spawns );
123+ }
110124
111- if (!list_empty (& inst -> alg .cra_users )) {
112- if (& n -> list == spawns )
113- n = list_entry (inst -> alg .cra_users .next ,
114- typeof (* n ), list );
115- __list_splice (& inst -> alg .cra_users , spawns -> prev );
116- }
125+ while (!list_empty (& secondary_spawns )) {
126+ list_for_each_entry_safe (spawn , n , & secondary_spawns , list )
127+ crypto_remove_spawn (spawn , list , & secondary_spawns );
117128 }
118129}
119130
@@ -164,7 +175,7 @@ static int __crypto_register_alg(struct crypto_alg *alg,
164175 q -> cra_priority > alg -> cra_priority )
165176 continue ;
166177
167- crypto_remove_spawns (& q -> cra_users , list );
178+ crypto_remove_spawns (& q -> cra_users , list , alg -> cra_flags );
168179 }
169180
170181 list_add (& alg -> cra_list , & crypto_alg_list );
@@ -214,7 +225,7 @@ static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list)
214225
215226 crypto_notify (CRYPTO_MSG_ALG_UNREGISTER , alg );
216227 list_del_init (& alg -> cra_list );
217- crypto_remove_spawns (& alg -> cra_users , list );
228+ crypto_remove_spawns (& alg -> cra_users , list , alg -> cra_flags );
218229
219230 return 0 ;
220231}
@@ -351,11 +362,12 @@ int crypto_register_instance(struct crypto_template *tmpl,
351362EXPORT_SYMBOL_GPL (crypto_register_instance );
352363
353364int crypto_init_spawn (struct crypto_spawn * spawn , struct crypto_alg * alg ,
354- struct crypto_instance * inst )
365+ struct crypto_instance * inst , u32 mask )
355366{
356367 int err = - EAGAIN ;
357368
358369 spawn -> inst = inst ;
370+ spawn -> mask = mask ;
359371
360372 down_write (& crypto_alg_sem );
361373 if (!crypto_is_moribund (alg )) {
@@ -494,7 +506,8 @@ struct crypto_instance *crypto_alloc_instance(const char *name,
494506 goto err_free_inst ;
495507
496508 spawn = crypto_instance_ctx (inst );
497- err = crypto_init_spawn (spawn , alg , inst );
509+ err = crypto_init_spawn (spawn , alg , inst ,
510+ CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC );
498511
499512 if (err )
500513 goto err_free_inst ;
0 commit comments