Skip to content

Commit fa3b356

Browse files
committed
crypto: api - Add __crypto_alloc_tfmgfp
Use it straight away in crypto_clone_cipher(), as that is not meant to sleep. Fixes: 51d8d6d ("crypto: cipher - Add crypto_clone_cipher") Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent fa919f9 commit fa3b356

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

crypto/api.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,15 @@ void crypto_shoot_alg(struct crypto_alg *alg)
386386
}
387387
EXPORT_SYMBOL_GPL(crypto_shoot_alg);
388388

389-
struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
390-
u32 mask)
389+
struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type,
390+
u32 mask, gfp_t gfp)
391391
{
392392
struct crypto_tfm *tfm = NULL;
393393
unsigned int tfm_size;
394394
int err = -ENOMEM;
395395

396396
tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask);
397-
tfm = kzalloc(tfm_size, GFP_KERNEL);
397+
tfm = kzalloc(tfm_size, gfp);
398398
if (tfm == NULL)
399399
goto out_err;
400400

@@ -416,6 +416,13 @@ struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
416416
out:
417417
return tfm;
418418
}
419+
EXPORT_SYMBOL_GPL(__crypto_alloc_tfmgfp);
420+
421+
struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
422+
u32 mask)
423+
{
424+
return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL);
425+
}
419426
EXPORT_SYMBOL_GPL(__crypto_alloc_tfm);
420427

421428
/*

crypto/cipher.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
101101
if (alg->cra_init)
102102
return ERR_PTR(-ENOSYS);
103103

104-
ntfm = __crypto_alloc_tfm(alg, CRYPTO_ALG_TYPE_CIPHER,
105-
CRYPTO_ALG_TYPE_MASK);
104+
ntfm = __crypto_alloc_tfmgfp(alg, CRYPTO_ALG_TYPE_CIPHER,
105+
CRYPTO_ALG_TYPE_MASK, GFP_ATOMIC);
106106
if (IS_ERR(ntfm))
107107
return ERR_CAST(ntfm);
108108

crypto/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
102102
struct crypto_alg *nalg);
103103
void crypto_remove_final(struct list_head *list);
104104
void crypto_shoot_alg(struct crypto_alg *alg);
105+
struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type,
106+
u32 mask, gfp_t gfp);
105107
struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
106108
u32 mask);
107109
void *crypto_create_tfm_node(struct crypto_alg *alg,

0 commit comments

Comments
 (0)