@@ -287,8 +287,9 @@ static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
287287 goto out ;
288288}
289289
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 )
292293{
293294 struct cryptd_instance_ctx * ctx ;
294295 struct crypto_instance * inst ;
@@ -298,7 +299,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
298299 alg = crypto_get_attr_alg (tb , CRYPTO_ALG_TYPE_BLKCIPHER ,
299300 CRYPTO_ALG_TYPE_MASK );
300301 if (IS_ERR (alg ))
301- return ERR_CAST (alg );
302+ return PTR_ERR (alg );
302303
303304 inst = cryptd_alloc_instance (alg , sizeof (* ctx ));
304305 if (IS_ERR (inst ))
@@ -330,14 +331,16 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
330331 inst -> alg .cra_ablkcipher .encrypt = cryptd_blkcipher_encrypt_enqueue ;
331332 inst -> alg .cra_ablkcipher .decrypt = cryptd_blkcipher_decrypt_enqueue ;
332333
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+
333341out_put_alg :
334342 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 ;
341344}
342345
343346static int cryptd_hash_init_tfm (struct crypto_tfm * tfm )
@@ -502,8 +505,8 @@ static int cryptd_hash_digest_enqueue(struct ahash_request *req)
502505 return cryptd_hash_enqueue (req , cryptd_hash_digest );
503506}
504507
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 )
507510{
508511 struct hashd_instance_ctx * ctx ;
509512 struct crypto_instance * inst ;
@@ -513,7 +516,7 @@ static struct crypto_instance *cryptd_alloc_hash(
513516
514517 salg = shash_attr_alg (tb [1 ], 0 , 0 );
515518 if (IS_ERR (salg ))
516- return ERR_CAST (salg );
519+ return PTR_ERR (salg );
517520
518521 alg = & salg -> base ;
519522 inst = cryptd_alloc_instance (alg , sizeof (* ctx ));
@@ -542,34 +545,36 @@ static struct crypto_instance *cryptd_alloc_hash(
542545 inst -> alg .cra_ahash .setkey = cryptd_hash_setkey ;
543546 inst -> alg .cra_ahash .digest = cryptd_hash_digest_enqueue ;
544547
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+
545555out_put_alg :
546556 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 ;
553558}
554559
555560static struct cryptd_queue queue ;
556561
557- static struct crypto_instance * cryptd_alloc ( struct rtattr * * tb )
562+ static int cryptd_create ( struct crypto_template * tmpl , struct rtattr * * tb )
558563{
559564 struct crypto_attr_type * algt ;
560565
561566 algt = crypto_get_attr_type (tb );
562567 if (IS_ERR (algt ))
563- return ERR_CAST (algt );
568+ return PTR_ERR (algt );
564569
565570 switch (algt -> type & algt -> mask & CRYPTO_ALG_TYPE_MASK ) {
566571 case CRYPTO_ALG_TYPE_BLKCIPHER :
567- return cryptd_alloc_blkcipher ( tb , & queue );
572+ return cryptd_create_blkcipher ( tmpl , tb , & queue );
568573 case CRYPTO_ALG_TYPE_DIGEST :
569- return cryptd_alloc_hash ( tb , & queue );
574+ return cryptd_create_hash ( tmpl , tb , & queue );
570575 }
571576
572- return ERR_PTR ( - EINVAL ) ;
577+ return - EINVAL ;
573578}
574579
575580static void cryptd_free (struct crypto_instance * inst )
@@ -582,7 +587,7 @@ static void cryptd_free(struct crypto_instance *inst)
582587
583588static struct crypto_template cryptd_tmpl = {
584589 .name = "cryptd" ,
585- .alloc = cryptd_alloc ,
590+ .create = cryptd_create ,
586591 .free = cryptd_free ,
587592 .module = THIS_MODULE ,
588593};
0 commit comments