aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/algapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r--crypto/algapi.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 60d7366ed343..395b082d03a9 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -62,7 +62,7 @@ static int crypto_check_alg(struct crypto_alg *alg)
62 if (alg->cra_priority < 0) 62 if (alg->cra_priority < 0)
63 return -EINVAL; 63 return -EINVAL;
64 64
65 atomic_set(&alg->cra_refcnt, 1); 65 refcount_set(&alg->cra_refcnt, 1);
66 66
67 return crypto_set_driver_name(alg); 67 return crypto_set_driver_name(alg);
68} 68}
@@ -123,7 +123,6 @@ static void crypto_remove_instance(struct crypto_instance *inst,
123 if (!tmpl || !crypto_tmpl_get(tmpl)) 123 if (!tmpl || !crypto_tmpl_get(tmpl))
124 return; 124 return;
125 125
126 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, &inst->alg);
127 list_move(&inst->alg.cra_list, list); 126 list_move(&inst->alg.cra_list, list);
128 hlist_del(&inst->list); 127 hlist_del(&inst->list);
129 inst->alg.cra_destroy = crypto_destroy_instance; 128 inst->alg.cra_destroy = crypto_destroy_instance;
@@ -167,6 +166,18 @@ void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
167 166
168 spawn->alg = NULL; 167 spawn->alg = NULL;
169 spawns = &inst->alg.cra_users; 168 spawns = &inst->alg.cra_users;
169
170 /*
171 * We may encounter an unregistered instance here, since
172 * an instance's spawns are set up prior to the instance
173 * being registered. An unregistered instance will have
174 * NULL ->cra_users.next, since ->cra_users isn't
175 * properly initialized until registration. But an
176 * unregistered instance cannot have any users, so treat
177 * it the same as ->cra_users being empty.
178 */
179 if (spawns->next == NULL)
180 break;
170 } 181 }
171 } while ((spawns = crypto_more_spawns(alg, &stack, &top, 182 } while ((spawns = crypto_more_spawns(alg, &stack, &top,
172 &secondary_spawns))); 183 &secondary_spawns)));
@@ -224,7 +235,7 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
224 if (!larval->adult) 235 if (!larval->adult)
225 goto free_larval; 236 goto free_larval;
226 237
227 atomic_set(&larval->alg.cra_refcnt, 1); 238 refcount_set(&larval->alg.cra_refcnt, 1);
228 memcpy(larval->alg.cra_driver_name, alg->cra_driver_name, 239 memcpy(larval->alg.cra_driver_name, alg->cra_driver_name,
229 CRYPTO_MAX_ALG_NAME); 240 CRYPTO_MAX_ALG_NAME);
230 larval->alg.cra_priority = alg->cra_priority; 241 larval->alg.cra_priority = alg->cra_priority;
@@ -380,7 +391,6 @@ static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list)
380 391
381 alg->cra_flags |= CRYPTO_ALG_DEAD; 392 alg->cra_flags |= CRYPTO_ALG_DEAD;
382 393
383 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, alg);
384 list_del_init(&alg->cra_list); 394 list_del_init(&alg->cra_list);
385 crypto_remove_spawns(alg, list, NULL); 395 crypto_remove_spawns(alg, list, NULL);
386 396
@@ -399,7 +409,7 @@ int crypto_unregister_alg(struct crypto_alg *alg)
399 if (ret) 409 if (ret)
400 return ret; 410 return ret;
401 411
402 BUG_ON(atomic_read(&alg->cra_refcnt) != 1); 412 BUG_ON(refcount_read(&alg->cra_refcnt) != 1);
403 if (alg->cra_destroy) 413 if (alg->cra_destroy)
404 alg->cra_destroy(alg); 414 alg->cra_destroy(alg);
405 415
@@ -458,7 +468,6 @@ int crypto_register_template(struct crypto_template *tmpl)
458 } 468 }
459 469
460 list_add(&tmpl->list, &crypto_template_list); 470 list_add(&tmpl->list, &crypto_template_list);
461 crypto_notify(CRYPTO_MSG_TMPL_REGISTER, tmpl);
462 err = 0; 471 err = 0;
463out: 472out:
464 up_write(&crypto_alg_sem); 473 up_write(&crypto_alg_sem);
@@ -485,12 +494,10 @@ void crypto_unregister_template(struct crypto_template *tmpl)
485 BUG_ON(err); 494 BUG_ON(err);
486 } 495 }
487 496
488 crypto_notify(CRYPTO_MSG_TMPL_UNREGISTER, tmpl);
489
490 up_write(&crypto_alg_sem); 497 up_write(&crypto_alg_sem);
491 498
492 hlist_for_each_entry_safe(inst, n, list, list) { 499 hlist_for_each_entry_safe(inst, n, list, list) {
493 BUG_ON(atomic_read(&inst->alg.cra_refcnt) != 1); 500 BUG_ON(refcount_read(&inst->alg.cra_refcnt) != 1);
494 crypto_free_instance(inst); 501 crypto_free_instance(inst);
495 } 502 }
496 crypto_remove_final(&users); 503 crypto_remove_final(&users);