crypto: sun8i-ss - do not allocate memory when handling hash requests
Instead of allocate memory on each requests, it is easier to pre-allocate buffers. This made error path easier. Signed-off-by: Corentin Labbe <clabbe@baylibre.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
4d867bebdc
commit
8eec4563f1
3 changed files with 17 additions and 12 deletions
|
@ -486,6 +486,16 @@ static int allocate_flows(struct sun8i_ss_dev *ss)
|
||||||
goto error_engine;
|
goto error_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* the padding could be up to two block. */
|
||||||
|
ss->flows[i].pad = devm_kmalloc(ss->dev, SHA256_BLOCK_SIZE * 2,
|
||||||
|
GFP_KERNEL | GFP_DMA);
|
||||||
|
if (!ss->flows[i].pad)
|
||||||
|
goto error_engine;
|
||||||
|
ss->flows[i].result = devm_kmalloc(ss->dev, SHA256_DIGEST_SIZE,
|
||||||
|
GFP_KERNEL | GFP_DMA);
|
||||||
|
if (!ss->flows[i].result)
|
||||||
|
goto error_engine;
|
||||||
|
|
||||||
ss->flows[i].engine = crypto_engine_alloc_init(ss->dev, true);
|
ss->flows[i].engine = crypto_engine_alloc_init(ss->dev, true);
|
||||||
if (!ss->flows[i].engine) {
|
if (!ss->flows[i].engine) {
|
||||||
dev_err(ss->dev, "Cannot allocate engine\n");
|
dev_err(ss->dev, "Cannot allocate engine\n");
|
||||||
|
|
|
@ -332,18 +332,11 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
|
||||||
if (digestsize == SHA224_DIGEST_SIZE)
|
if (digestsize == SHA224_DIGEST_SIZE)
|
||||||
digestsize = SHA256_DIGEST_SIZE;
|
digestsize = SHA256_DIGEST_SIZE;
|
||||||
|
|
||||||
/* the padding could be up to two block. */
|
result = ss->flows[rctx->flow].result;
|
||||||
pad = kzalloc(algt->alg.hash.halg.base.cra_blocksize * 2, GFP_KERNEL | GFP_DMA);
|
pad = ss->flows[rctx->flow].pad;
|
||||||
if (!pad)
|
memset(pad, 0, algt->alg.hash.halg.base.cra_blocksize * 2);
|
||||||
return -ENOMEM;
|
|
||||||
bf = (__le32 *)pad;
|
bf = (__le32 *)pad;
|
||||||
|
|
||||||
result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA);
|
|
||||||
if (!result) {
|
|
||||||
kfree(pad);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_SG; i++) {
|
for (i = 0; i < MAX_SG; i++) {
|
||||||
rctx->t_dst[i].addr = 0;
|
rctx->t_dst[i].addr = 0;
|
||||||
rctx->t_dst[i].len = 0;
|
rctx->t_dst[i].len = 0;
|
||||||
|
@ -439,8 +432,6 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
|
||||||
|
|
||||||
memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
|
memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
|
||||||
theend:
|
theend:
|
||||||
kfree(pad);
|
|
||||||
kfree(result);
|
|
||||||
local_bh_disable();
|
local_bh_disable();
|
||||||
crypto_finalize_hash_request(engine, breq, err);
|
crypto_finalize_hash_request(engine, breq, err);
|
||||||
local_bh_enable();
|
local_bh_enable();
|
||||||
|
|
|
@ -123,6 +123,8 @@ struct sginfo {
|
||||||
* @stat_req: number of request done by this flow
|
* @stat_req: number of request done by this flow
|
||||||
* @iv: list of IV to use for each step
|
* @iv: list of IV to use for each step
|
||||||
* @biv: buffer which contain the backuped IV
|
* @biv: buffer which contain the backuped IV
|
||||||
|
* @pad: padding buffer for hash operations
|
||||||
|
* @result: buffer for storing the result of hash operations
|
||||||
*/
|
*/
|
||||||
struct sun8i_ss_flow {
|
struct sun8i_ss_flow {
|
||||||
struct crypto_engine *engine;
|
struct crypto_engine *engine;
|
||||||
|
@ -130,6 +132,8 @@ struct sun8i_ss_flow {
|
||||||
int status;
|
int status;
|
||||||
u8 *iv[MAX_SG];
|
u8 *iv[MAX_SG];
|
||||||
u8 *biv;
|
u8 *biv;
|
||||||
|
void *pad;
|
||||||
|
void *result;
|
||||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_DEBUG
|
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_DEBUG
|
||||||
unsigned long stat_req;
|
unsigned long stat_req;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue