diff options
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/algapi.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c index 56c62e2858d5..429f1a003b06 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c | |||
| @@ -627,17 +627,20 @@ int crypto_attr_u32(struct rtattr *rta, u32 *num) | |||
| 627 | } | 627 | } |
| 628 | EXPORT_SYMBOL_GPL(crypto_attr_u32); | 628 | EXPORT_SYMBOL_GPL(crypto_attr_u32); |
| 629 | 629 | ||
| 630 | struct crypto_instance *crypto_alloc_instance(const char *name, | 630 | void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg, |
| 631 | struct crypto_alg *alg) | 631 | unsigned int head) |
| 632 | { | 632 | { |
| 633 | struct crypto_instance *inst; | 633 | struct crypto_instance *inst; |
| 634 | struct crypto_spawn *spawn; | 634 | char *p; |
| 635 | int err; | 635 | int err; |
| 636 | 636 | ||
| 637 | inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); | 637 | p = kzalloc(head + sizeof(*inst) + sizeof(struct crypto_spawn), |
| 638 | if (!inst) | 638 | GFP_KERNEL); |
| 639 | if (!p) | ||
| 639 | return ERR_PTR(-ENOMEM); | 640 | return ERR_PTR(-ENOMEM); |
| 640 | 641 | ||
| 642 | inst = (void *)(p + head); | ||
| 643 | |||
| 641 | err = -ENAMETOOLONG; | 644 | err = -ENAMETOOLONG; |
| 642 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, | 645 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, |
| 643 | alg->cra_name) >= CRYPTO_MAX_ALG_NAME) | 646 | alg->cra_name) >= CRYPTO_MAX_ALG_NAME) |
| @@ -647,6 +650,25 @@ struct crypto_instance *crypto_alloc_instance(const char *name, | |||
| 647 | name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) | 650 | name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) |
| 648 | goto err_free_inst; | 651 | goto err_free_inst; |
| 649 | 652 | ||
| 653 | return p; | ||
| 654 | |||
| 655 | err_free_inst: | ||
| 656 | kfree(p); | ||
| 657 | return ERR_PTR(err); | ||
| 658 | } | ||
| 659 | EXPORT_SYMBOL_GPL(crypto_alloc_instance2); | ||
| 660 | |||
| 661 | struct crypto_instance *crypto_alloc_instance(const char *name, | ||
| 662 | struct crypto_alg *alg) | ||
| 663 | { | ||
| 664 | struct crypto_instance *inst; | ||
| 665 | struct crypto_spawn *spawn; | ||
| 666 | int err; | ||
| 667 | |||
| 668 | inst = crypto_alloc_instance2(name, alg, 0); | ||
| 669 | if (IS_ERR(inst)) | ||
| 670 | goto out; | ||
| 671 | |||
| 650 | spawn = crypto_instance_ctx(inst); | 672 | spawn = crypto_instance_ctx(inst); |
| 651 | err = crypto_init_spawn(spawn, alg, inst, | 673 | err = crypto_init_spawn(spawn, alg, inst, |
| 652 | CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 674 | CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); |
| @@ -658,7 +680,10 @@ struct crypto_instance *crypto_alloc_instance(const char *name, | |||
| 658 | 680 | ||
| 659 | err_free_inst: | 681 | err_free_inst: |
| 660 | kfree(inst); | 682 | kfree(inst); |
| 661 | return ERR_PTR(err); | 683 | inst = ERR_PTR(err); |
| 684 | |||
| 685 | out: | ||
| 686 | return inst; | ||
| 662 | } | 687 | } |
| 663 | EXPORT_SYMBOL_GPL(crypto_alloc_instance); | 688 | EXPORT_SYMBOL_GPL(crypto_alloc_instance); |
| 664 | 689 | ||
