crypto: sun8i-ce: Fix `dma_unmap_sg()` nents value
PATCH 1/1 crypto: sun8i-ce: Fix `dma_unmap_sg()` nents value
The dma_unmap_sg() functions should be called with the same nents as the dma_map_sg(), not the value the map function returned.
Fixes 0605fa0f7826 ("crypto: sun8i-ce - split into prepare/run/unprepare")
Signed-off-by Thomas Fourier <[email protected]>
--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +6 -6
@@ -326,8 +326,8 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine,struct sun8i_ce_flow *chan;struct ce_task *cet;unsigned int ivsize, offset; -int nr_sgs = rctx->nr_sgs; -int nr_sgd = rctx->nr_sgd; +int ns =sg_nents_for_len (areq->src, areq->cryptlen); +int nd =sg_nents_for_len (areq->dst, areq->cryptlen);int flow; flow = rctx->flow;
@@ -336,11 +336,11 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine, ivsize =crypto_skcipher_ivsize (tfm);if (areq->src == areq->dst) { -dma_unmap_sg (ce->dev, areq->src, nr_sgs,DMA_BIDIRECTIONAL ); +dma_unmap_sg (ce->dev, areq->src, ns,DMA_BIDIRECTIONAL ); }else { -if (nr_sgs >0 ) -dma_unmap_sg (ce->dev, areq->src, nr_sgs,DMA_TO_DEVICE ); -dma_unmap_sg (ce->dev, areq->dst, nr_sgd,DMA_FROM_DEVICE ); +if (rctx->nr_sgs >0 ) +dma_unmap_sg (ce->dev, areq->src, ns,DMA_TO_DEVICE ); +dma_unmap_sg (ce->dev, areq->dst, nd,DMA_FROM_DEVICE ); }if (areq->iv && ivsize >0 ) {
Signature · 1 line
2.43.0
Hi Thomas,
Quoted 3 lines · Thomas Fourier
The
dma_unmap_sg()functions should be called with the same nents as thedma_map_sg(), not the value the map function returned.
This should already be fixed by:
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git/commit/?id=b6cd3cfb5afe49952f8f6be947aeeca9ba0faebb
The sg nents are saved to request context during prepare() and then used in unprepare().
Thanks,
Ovidiu
Quoted 37 lines
Fixes 0605fa0f7826 ("crypto: sun8i-ce - split into prepare/run/unprepare")Signed-off-by Thomas Fourier <[email protected]>--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +6
-6@@ -326,8 +326,8 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine,struct sun8i_ce_flow *chan;struct ce_task *cet;unsigned int ivsize, offset; -int nr_sgs = rctx->nr_sgs; -int nr_sgd = rctx->nr_sgd; +int ns =sg_nents_for_len (areq->src, areq->cryptlen); +int nd =sg_nents_for_len (areq->dst, areq->cryptlen);int flow; flow = rctx->flow;@@ -336,11 +336,11 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine, ivsize =crypto_skcipher_ivsize (tfm);if (areq->src == areq->dst) { -dma_unmap_sg (ce->dev, areq->src, nr_sgs,DMA_BIDIRECTIONAL ); +dma_unmap_sg (ce->dev, areq->src, ns,DMA_BIDIRECTIONAL ); }else { -if (nr_sgs >0 ) -dma_unmap_sg (ce->dev, areq->src, nr_sgs,DMA_TO_DEVICE ); -dma_unmap_sg (ce->dev, areq->dst, nr_sgd,DMA_FROM_DEVICE ); +if (rctx->nr_sgs >0 ) +dma_unmap_sg (ce->dev, areq->src, ns,DMA_TO_DEVICE ); +dma_unmap_sg (ce->dev, areq->dst, nd,DMA_FROM_DEVICE ); }if (areq->iv && ivsize >0 ) {