Commit fd88aac9 authored by Horia Geantă's avatar Horia Geantă Committed by Herbert Xu

crypto: caam - fix HW S/G in ablkcipher_giv_edesc_alloc()

HW S/G generation does not work properly when the following conditions
are met:
-src == dst
-src/dst is S/G
-IV is right before (contiguous with) the first src/dst S/G entry
since "iv_contig" is set to true (iv_contig is a misnomer here and
it actually refers to the whole output being contiguous)

Fix this by setting dst S/G nents equal to src S/G nents, instead of
leaving it set to init value (0).
Signed-off-by: default avatarHoria Geantă <horia.geanta@nxp.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 4d8348d8
...@@ -1798,7 +1798,7 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc( ...@@ -1798,7 +1798,7 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
CRYPTO_TFM_REQ_MAY_SLEEP)) ? CRYPTO_TFM_REQ_MAY_SLEEP)) ?
GFP_KERNEL : GFP_ATOMIC; GFP_KERNEL : GFP_ATOMIC;
int src_nents, dst_nents = 0, sec4_sg_bytes; int src_nents, dst_nents, sec4_sg_bytes;
struct ablkcipher_edesc *edesc; struct ablkcipher_edesc *edesc;
dma_addr_t iv_dma = 0; dma_addr_t iv_dma = 0;
bool iv_contig = false; bool iv_contig = false;
...@@ -1808,9 +1808,6 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc( ...@@ -1808,9 +1808,6 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
src_nents = sg_count(req->src, req->nbytes); src_nents = sg_count(req->src, req->nbytes);
if (unlikely(req->dst != req->src))
dst_nents = sg_count(req->dst, req->nbytes);
if (likely(req->src == req->dst)) { if (likely(req->src == req->dst)) {
sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1, sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
DMA_BIDIRECTIONAL); DMA_BIDIRECTIONAL);
...@@ -1818,6 +1815,8 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc( ...@@ -1818,6 +1815,8 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
dev_err(jrdev, "unable to map source\n"); dev_err(jrdev, "unable to map source\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
dst_nents = src_nents;
} else { } else {
sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1, sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
DMA_TO_DEVICE); DMA_TO_DEVICE);
...@@ -1826,6 +1825,7 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc( ...@@ -1826,6 +1825,7 @@ static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
dst_nents = sg_count(req->dst, req->nbytes);
sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1, sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
if (unlikely(!sgc)) { if (unlikely(!sgc)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment