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:
Родитель
4d867bebdc
Коммит
8eec4563f1
|
@ -486,6 +486,16 @@ static int allocate_flows(struct sun8i_ss_dev *ss)
|
|||
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);
|
||||
if (!ss->flows[i].engine) {
|
||||
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)
|
||||
digestsize = SHA256_DIGEST_SIZE;
|
||||
|
||||
/* the padding could be up to two block. */
|
||||
pad = kzalloc(algt->alg.hash.halg.base.cra_blocksize * 2, GFP_KERNEL | GFP_DMA);
|
||||
if (!pad)
|
||||
return -ENOMEM;
|
||||
result = ss->flows[rctx->flow].result;
|
||||
pad = ss->flows[rctx->flow].pad;
|
||||
memset(pad, 0, algt->alg.hash.halg.base.cra_blocksize * 2);
|
||||
bf = (__le32 *)pad;
|
||||
|
||||
result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA);
|
||||
if (!result) {
|
||||
kfree(pad);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_SG; i++) {
|
||||
rctx->t_dst[i].addr = 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);
|
||||
theend:
|
||||
kfree(pad);
|
||||
kfree(result);
|
||||
local_bh_disable();
|
||||
crypto_finalize_hash_request(engine, breq, err);
|
||||
local_bh_enable();
|
||||
|
|
|
@ -123,6 +123,8 @@ struct sginfo {
|
|||
* @stat_req: number of request done by this flow
|
||||
* @iv: list of IV to use for each step
|
||||
* @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 crypto_engine *engine;
|
||||
|
@ -130,6 +132,8 @@ struct sun8i_ss_flow {
|
|||
int status;
|
||||
u8 *iv[MAX_SG];
|
||||
u8 *biv;
|
||||
void *pad;
|
||||
void *result;
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_DEBUG
|
||||
unsigned long stat_req;
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче