Skip to content

Commit

Permalink
crypto: ccp - Apply appropriate gfp_t type to memory allocations
Browse files Browse the repository at this point in the history
Fix some memory allocations to use the appropriate gfp_t type based
on the CRYPTO_TFM_REQ_MAY_SLEEP flag.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Tom Lendacky authored and Herbert Xu committed Jan 15, 2014
1 parent d16b870 commit 5258de8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion drivers/crypto/ccp/ccp-crypto-aes-cmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static int ccp_do_cmac_update(struct ahash_request *req, unsigned int nbytes,
unsigned int block_size =
crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
unsigned int len, need_pad, sg_count;
gfp_t gfp;
int ret;

if (!ctx->u.aes.key_len)
Expand Down Expand Up @@ -99,7 +100,9 @@ static int ccp_do_cmac_update(struct ahash_request *req, unsigned int nbytes,
* possible data pieces (buffer, input data, padding)
*/
sg_count = (nbytes) ? sg_nents(req->src) + 2 : 2;
ret = sg_alloc_table(&rctx->data_sg, sg_count, GFP_KERNEL);
gfp = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
GFP_KERNEL : GFP_ATOMIC;
ret = sg_alloc_table(&rctx->data_sg, sg_count, gfp);
if (ret)
return ret;

Expand Down
5 changes: 4 additions & 1 deletion drivers/crypto/ccp/ccp-crypto-sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static int ccp_do_sha_update(struct ahash_request *req, unsigned int nbytes,
unsigned int block_size =
crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
unsigned int len, sg_count;
gfp_t gfp;
int ret;

if (!final && ((nbytes + rctx->buf_count) <= block_size)) {
Expand Down Expand Up @@ -156,7 +157,9 @@ static int ccp_do_sha_update(struct ahash_request *req, unsigned int nbytes,
* possible data pieces (hmac ipad, buffer, input data)
*/
sg_count = (nbytes) ? sg_nents(req->src) + 2 : 2;
ret = sg_alloc_table(&rctx->data_sg, sg_count, GFP_KERNEL);
gfp = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
GFP_KERNEL : GFP_ATOMIC;
ret = sg_alloc_table(&rctx->data_sg, sg_count, gfp);
if (ret)
return ret;

Expand Down

0 comments on commit 5258de8

Please sign in to comment.