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: vmac - use crypto_grab_cipher() and simplify error paths

Make the vmac64 template use the new function crypto_grab_cipher() to
initialize its cipher spawn.

This is needed to make all spawns be initialized in a consistent way.

This required making vmac_create() allocate the instance directly rather
than use shash_alloc_instance().

Also simplify the error handling by taking advantage of crypto_drop_*()
now accepting (as a no-op) spawns that haven't been initialized yet, and
by taking advantage of crypto_grab_*() now handling ERR_PTR() names.

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
3b4e73d8 1d0459cd

+15 -18
+15 -18
crypto/vmac.c
··· 618 618 static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb) 619 619 { 620 620 struct shash_instance *inst; 621 + struct crypto_cipher_spawn *spawn; 621 622 struct crypto_alg *alg; 622 623 int err; 623 624 ··· 626 625 if (err) 627 626 return err; 628 627 629 - alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, 630 - CRYPTO_ALG_TYPE_MASK); 631 - if (IS_ERR(alg)) 632 - return PTR_ERR(alg); 628 + inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); 629 + if (!inst) 630 + return -ENOMEM; 631 + spawn = shash_instance_ctx(inst); 632 + 633 + err = crypto_grab_cipher(spawn, shash_crypto_instance(inst), 634 + crypto_attr_alg_name(tb[1]), 0, 0); 635 + if (err) 636 + goto err_free_inst; 637 + alg = crypto_spawn_cipher_alg(spawn); 633 638 634 639 err = -EINVAL; 635 640 if (alg->cra_blocksize != VMAC_NONCEBYTES) 636 - goto out_put_alg; 641 + goto err_free_inst; 637 642 638 - inst = shash_alloc_instance(tmpl->name, alg); 639 - err = PTR_ERR(inst); 640 - if (IS_ERR(inst)) 641 - goto out_put_alg; 642 - 643 - err = crypto_init_spawn(shash_instance_ctx(inst), alg, 644 - shash_crypto_instance(inst), 645 - CRYPTO_ALG_TYPE_MASK); 643 + err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg); 646 644 if (err) 647 - goto out_free_inst; 645 + goto err_free_inst; 648 646 649 647 inst->alg.base.cra_priority = alg->cra_priority; 650 648 inst->alg.base.cra_blocksize = alg->cra_blocksize; ··· 662 662 663 663 err = shash_register_instance(tmpl, inst); 664 664 if (err) { 665 - out_free_inst: 665 + err_free_inst: 666 666 shash_free_instance(shash_crypto_instance(inst)); 667 667 } 668 - 669 - out_put_alg: 670 - crypto_mod_put(alg); 671 668 return err; 672 669 } 673 670