Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: inside-secure - 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: c957f8b3e2e5 ("crypto: inside-secure - avoid unmapping DMA memory that was not mapped")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Reviewed-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Thomas Fourier and committed by
Herbert Xu
cb7fa6b6 b4abeccb

+6 -2
+6 -2
drivers/crypto/inside-secure/safexcel_hash.c
··· 249 249 safexcel_complete(priv, ring); 250 250 251 251 if (sreq->nents) { 252 - dma_unmap_sg(priv->dev, areq->src, sreq->nents, DMA_TO_DEVICE); 252 + dma_unmap_sg(priv->dev, areq->src, 253 + sg_nents_for_len(areq->src, areq->nbytes), 254 + DMA_TO_DEVICE); 253 255 sreq->nents = 0; 254 256 } 255 257 ··· 499 497 DMA_FROM_DEVICE); 500 498 unmap_sg: 501 499 if (req->nents) { 502 - dma_unmap_sg(priv->dev, areq->src, req->nents, DMA_TO_DEVICE); 500 + dma_unmap_sg(priv->dev, areq->src, 501 + sg_nents_for_len(areq->src, areq->nbytes), 502 + DMA_TO_DEVICE); 503 503 req->nents = 0; 504 504 } 505 505 cdesc_rollback: