Commit 9cd899a32f611eb6328014f1d9e0ba31977812d9
1 parent
52861c7cd7
crypto: cryptd - Switch to template create API
This patch changes cryptd to use the template->create function instead of alloc in anticipation for the switch to new style ahash algorithms. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 3 changed files with 32 additions and 27 deletions Side-by-side Diff
crypto/cryptd.c
... | ... | @@ -287,8 +287,9 @@ |
287 | 287 | goto out; |
288 | 288 | } |
289 | 289 | |
290 | -static struct crypto_instance *cryptd_alloc_blkcipher( | |
291 | - struct rtattr **tb, struct cryptd_queue *queue) | |
290 | +static int cryptd_create_blkcipher(struct crypto_template *tmpl, | |
291 | + struct rtattr **tb, | |
292 | + struct cryptd_queue *queue) | |
292 | 293 | { |
293 | 294 | struct cryptd_instance_ctx *ctx; |
294 | 295 | struct crypto_instance *inst; |
... | ... | @@ -298,7 +299,7 @@ |
298 | 299 | alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER, |
299 | 300 | CRYPTO_ALG_TYPE_MASK); |
300 | 301 | if (IS_ERR(alg)) |
301 | - return ERR_CAST(alg); | |
302 | + return PTR_ERR(alg); | |
302 | 303 | |
303 | 304 | inst = cryptd_alloc_instance(alg, sizeof(*ctx)); |
304 | 305 | if (IS_ERR(inst)) |
305 | 306 | |
... | ... | @@ -330,14 +331,16 @@ |
330 | 331 | inst->alg.cra_ablkcipher.encrypt = cryptd_blkcipher_encrypt_enqueue; |
331 | 332 | inst->alg.cra_ablkcipher.decrypt = cryptd_blkcipher_decrypt_enqueue; |
332 | 333 | |
334 | + err = crypto_register_instance(tmpl, inst); | |
335 | + if (err) { | |
336 | + crypto_drop_spawn(&ctx->spawn); | |
337 | +out_free_inst: | |
338 | + kfree(inst); | |
339 | + } | |
340 | + | |
333 | 341 | out_put_alg: |
334 | 342 | crypto_mod_put(alg); |
335 | - return inst; | |
336 | - | |
337 | -out_free_inst: | |
338 | - kfree(inst); | |
339 | - inst = ERR_PTR(err); | |
340 | - goto out_put_alg; | |
343 | + return err; | |
341 | 344 | } |
342 | 345 | |
343 | 346 | static int cryptd_hash_init_tfm(struct crypto_tfm *tfm) |
... | ... | @@ -502,8 +505,8 @@ |
502 | 505 | return cryptd_hash_enqueue(req, cryptd_hash_digest); |
503 | 506 | } |
504 | 507 | |
505 | -static struct crypto_instance *cryptd_alloc_hash( | |
506 | - struct rtattr **tb, struct cryptd_queue *queue) | |
508 | +static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, | |
509 | + struct cryptd_queue *queue) | |
507 | 510 | { |
508 | 511 | struct hashd_instance_ctx *ctx; |
509 | 512 | struct crypto_instance *inst; |
... | ... | @@ -513,7 +516,7 @@ |
513 | 516 | |
514 | 517 | salg = shash_attr_alg(tb[1], 0, 0); |
515 | 518 | if (IS_ERR(salg)) |
516 | - return ERR_CAST(salg); | |
519 | + return PTR_ERR(salg); | |
517 | 520 | |
518 | 521 | alg = &salg->base; |
519 | 522 | inst = cryptd_alloc_instance(alg, sizeof(*ctx)); |
520 | 523 | |
521 | 524 | |
522 | 525 | |
523 | 526 | |
524 | 527 | |
525 | 528 | |
... | ... | @@ -542,34 +545,36 @@ |
542 | 545 | inst->alg.cra_ahash.setkey = cryptd_hash_setkey; |
543 | 546 | inst->alg.cra_ahash.digest = cryptd_hash_digest_enqueue; |
544 | 547 | |
548 | + err = crypto_register_instance(tmpl, inst); | |
549 | + if (err) { | |
550 | + crypto_drop_shash(&ctx->spawn); | |
551 | +out_free_inst: | |
552 | + kfree(inst); | |
553 | + } | |
554 | + | |
545 | 555 | out_put_alg: |
546 | 556 | crypto_mod_put(alg); |
547 | - return inst; | |
548 | - | |
549 | -out_free_inst: | |
550 | - kfree(inst); | |
551 | - inst = ERR_PTR(err); | |
552 | - goto out_put_alg; | |
557 | + return err; | |
553 | 558 | } |
554 | 559 | |
555 | 560 | static struct cryptd_queue queue; |
556 | 561 | |
557 | -static struct crypto_instance *cryptd_alloc(struct rtattr **tb) | |
562 | +static int cryptd_create(struct crypto_template *tmpl, struct rtattr **tb) | |
558 | 563 | { |
559 | 564 | struct crypto_attr_type *algt; |
560 | 565 | |
561 | 566 | algt = crypto_get_attr_type(tb); |
562 | 567 | if (IS_ERR(algt)) |
563 | - return ERR_CAST(algt); | |
568 | + return PTR_ERR(algt); | |
564 | 569 | |
565 | 570 | switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) { |
566 | 571 | case CRYPTO_ALG_TYPE_BLKCIPHER: |
567 | - return cryptd_alloc_blkcipher(tb, &queue); | |
572 | + return cryptd_create_blkcipher(tmpl, tb, &queue); | |
568 | 573 | case CRYPTO_ALG_TYPE_DIGEST: |
569 | - return cryptd_alloc_hash(tb, &queue); | |
574 | + return cryptd_create_hash(tmpl, tb, &queue); | |
570 | 575 | } |
571 | 576 | |
572 | - return ERR_PTR(-EINVAL); | |
577 | + return -EINVAL; | |
573 | 578 | } |
574 | 579 | |
575 | 580 | static void cryptd_free(struct crypto_instance *inst) |
... | ... | @@ -582,7 +587,7 @@ |
582 | 587 | |
583 | 588 | static struct crypto_template cryptd_tmpl = { |
584 | 589 | .name = "cryptd", |
585 | - .alloc = cryptd_alloc, | |
590 | + .create = cryptd_create, | |
586 | 591 | .free = cryptd_free, |
587 | 592 | .module = THIS_MODULE, |
588 | 593 | }; |
crypto/internal.h
... | ... | @@ -97,9 +97,6 @@ |
97 | 97 | void *crypto_alloc_tfm(const char *alg_name, |
98 | 98 | const struct crypto_type *frontend, u32 type, u32 mask); |
99 | 99 | |
100 | -int crypto_register_instance(struct crypto_template *tmpl, | |
101 | - struct crypto_instance *inst); | |
102 | - | |
103 | 100 | int crypto_register_notifier(struct notifier_block *nb); |
104 | 101 | int crypto_unregister_notifier(struct notifier_block *nb); |
105 | 102 | int crypto_probing_notify(unsigned long val, void *v); |
include/crypto/algapi.h
... | ... | @@ -114,6 +114,9 @@ |
114 | 114 | void crypto_unregister_template(struct crypto_template *tmpl); |
115 | 115 | struct crypto_template *crypto_lookup_template(const char *name); |
116 | 116 | |
117 | +int crypto_register_instance(struct crypto_template *tmpl, | |
118 | + struct crypto_instance *inst); | |
119 | + | |
117 | 120 | int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, |
118 | 121 | struct crypto_instance *inst, u32 mask); |
119 | 122 | int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg, |