Skip to content

Commit 70ec7bb

Browse files
committed
crypto: api - Add crypto_alloc_instance2
This patch adds a new argument to crypto_alloc_instance which sets aside some space before the instance for use by algorithms such as shash that place type-specific data before crypto_alg. For compatibility the function has been renamed so that existing users aren't affected. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent f2ac72e commit 70ec7bb

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎crypto/algapi.c‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -627,17 +627,20 @@ int crypto_attr_u32(struct rtattr *rta, u32 *num)
627627
}
628628
EXPORT_SYMBOL_GPL(crypto_attr_u32);
629629

630-
struct crypto_instance *crypto_alloc_instance(const char *name,
631-
struct crypto_alg *alg)
630+
void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg,
631+
unsigned int head)
632632
{
633633
struct crypto_instance *inst;
634-
struct crypto_spawn *spawn;
634+
char *p;
635635
int err;
636636

637-
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
638-
if (!inst)
637+
p = kzalloc(head + sizeof(*inst) + sizeof(struct crypto_spawn),
638+
GFP_KERNEL);
639+
if (!p)
639640
return ERR_PTR(-ENOMEM);
640641

642+
inst = (void *)(p + head);
643+
641644
err = -ENAMETOOLONG;
642645
if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name,
643646
alg->cra_name) >= CRYPTO_MAX_ALG_NAME)
@@ -647,6 +650,25 @@ struct crypto_instance *crypto_alloc_instance(const char *name,
647650
name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
648651
goto err_free_inst;
649652

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+
650672
spawn = crypto_instance_ctx(inst);
651673
err = crypto_init_spawn(spawn, alg, inst,
652674
CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
@@ -658,7 +680,10 @@ struct crypto_instance *crypto_alloc_instance(const char *name,
658680

659681
err_free_inst:
660682
kfree(inst);
661-
return ERR_PTR(err);
683+
inst = ERR_PTR(err);
684+
685+
out:
686+
return inst;
662687
}
663688
EXPORT_SYMBOL_GPL(crypto_alloc_instance);
664689

‎include/crypto/algapi.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ int crypto_check_attr_type(struct rtattr **tb, u32 type);
132132
const char *crypto_attr_alg_name(struct rtattr *rta);
133133
struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask);
134134
int crypto_attr_u32(struct rtattr *rta, u32 *num);
135+
void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg,
136+
unsigned int head);
135137
struct crypto_instance *crypto_alloc_instance(const char *name,
136138
struct crypto_alg *alg);
137139

0 commit comments

Comments
 (0)