Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: algapi - fold crypto_init_spawn() into crypto_grab_spawn()

Now that crypto_init_spawn() is only called by crypto_grab_spawn(),
simplify things by moving its functionality into crypto_grab_spawn().

In the process of doing this, also be more consistent about when the
spawn and instance are updated, and remove the crypto_spawn::dropref
flag since now it's always set.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
aed11cf5 6d1b41fc

+16 -34
+16 -31
crypto/algapi.c
··· 629 629 spawn->inst = inst; 630 630 spawn->registered = true; 631 631 632 - if (spawn->dropref) 633 - crypto_mod_put(spawn->alg); 632 + crypto_mod_put(spawn->alg); 634 633 635 634 spawn = next; 636 635 } ··· 671 672 } 672 673 EXPORT_SYMBOL_GPL(crypto_unregister_instance); 673 674 674 - int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, 675 - struct crypto_instance *inst, u32 mask) 676 - { 677 - int err = -EAGAIN; 678 - 679 - if (WARN_ON_ONCE(inst == NULL)) 680 - return -EINVAL; 681 - 682 - spawn->next = inst->spawns; 683 - inst->spawns = spawn; 684 - 685 - spawn->mask = mask; 686 - 687 - down_write(&crypto_alg_sem); 688 - if (!crypto_is_moribund(alg)) { 689 - list_add(&spawn->list, &alg->cra_users); 690 - spawn->alg = alg; 691 - err = 0; 692 - } 693 - up_write(&crypto_alg_sem); 694 - 695 - return err; 696 - } 697 - EXPORT_SYMBOL_GPL(crypto_init_spawn); 698 - 699 675 int crypto_grab_spawn(struct crypto_spawn *spawn, struct crypto_instance *inst, 700 676 const char *name, u32 type, u32 mask) 701 677 { 702 678 struct crypto_alg *alg; 703 - int err; 679 + int err = -EAGAIN; 680 + 681 + if (WARN_ON_ONCE(inst == NULL)) 682 + return -EINVAL; 704 683 705 684 /* Allow the result of crypto_attr_alg_name() to be passed directly */ 706 685 if (IS_ERR(name)) ··· 688 711 if (IS_ERR(alg)) 689 712 return PTR_ERR(alg); 690 713 691 - spawn->dropref = true; 692 - err = crypto_init_spawn(spawn, alg, inst, mask); 714 + down_write(&crypto_alg_sem); 715 + if (!crypto_is_moribund(alg)) { 716 + list_add(&spawn->list, &alg->cra_users); 717 + spawn->alg = alg; 718 + spawn->mask = mask; 719 + spawn->next = inst->spawns; 720 + inst->spawns = spawn; 721 + err = 0; 722 + } 723 + up_write(&crypto_alg_sem); 693 724 if (err) 694 725 crypto_mod_put(alg); 695 726 return err; ··· 714 729 list_del(&spawn->list); 715 730 up_write(&crypto_alg_sem); 716 731 717 - if (spawn->dropref && !spawn->registered) 732 + if (!spawn->registered) 718 733 crypto_mod_put(spawn->alg); 719 734 } 720 735 EXPORT_SYMBOL_GPL(crypto_drop_spawn);
-3
include/crypto/algapi.h
··· 82 82 const struct crypto_type *frontend; 83 83 u32 mask; 84 84 bool dead; 85 - bool dropref; 86 85 bool registered; 87 86 }; 88 87 ··· 110 111 struct crypto_instance *inst); 111 112 void crypto_unregister_instance(struct crypto_instance *inst); 112 113 113 - int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, 114 - struct crypto_instance *inst, u32 mask); 115 114 int crypto_grab_spawn(struct crypto_spawn *spawn, struct crypto_instance *inst, 116 115 const char *name, u32 type, u32 mask); 117 116 void crypto_drop_spawn(struct crypto_spawn *spawn);