mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: inside-secure: Fix `dma_unmap_sg()` nents value
@ 2025-06-19 15:28 fourier.thomas
  2025-06-19 18:10 ` Antoine Tenart
  0 siblings, 1 reply; 2+ messages in thread
From: fourier.thomas @ 2025-06-19 15:28 UTC (permalink / raw)
  Cc: Thomas Fourier, Antoine Tenart, Herbert Xu, David S. Miller,
	linux-crypto, linux-kernel

From: Thomas Fourier <fourier.thomas@gmail.com>

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>
---
 drivers/crypto/inside-secure/safexcel_hash.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/inside-secure/safexcel_hash.c
index d2b632193beb..1ef1ccfaaa95 100644
--- a/drivers/crypto/inside-secure/safexcel_hash.c
+++ b/drivers/crypto/inside-secure/safexcel_hash.c
@@ -249,7 +249,10 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv,
 	safexcel_complete(priv, ring);
 
 	if (sreq->nents) {
-		dma_unmap_sg(priv->dev, areq->src, sreq->nents, DMA_TO_DEVICE);
+		dma_unmap_sg(priv->dev,
+			     areq->src,
+			     sg_nents_for_len(areq->src, areq->nbytes),
+			     DMA_TO_DEVICE);
 		sreq->nents = 0;
 	}
 
@@ -497,7 +500,10 @@ static int safexcel_ahash_send_req(struct crypto_async_request *async, int ring,
 			 DMA_FROM_DEVICE);
 unmap_sg:
 	if (req->nents) {
-		dma_unmap_sg(priv->dev, areq->src, req->nents, DMA_TO_DEVICE);
+		dma_unmap_sg(priv->dev,
+			     areq->src,
+			     sg_nents_for_len(areq->src, areq->nbytes),
+			     DMA_TO_DEVICE);
 		req->nents = 0;
 	}
 cdesc_rollback:
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: inside-secure: Fix `dma_unmap_sg()` nents value
  2025-06-19 15:28 [PATCH] crypto: inside-secure: Fix `dma_unmap_sg()` nents value fourier.thomas
@ 2025-06-19 18:10 ` Antoine Tenart
  0 siblings, 0 replies; 2+ messages in thread
From: Antoine Tenart @ 2025-06-19 18:10 UTC (permalink / raw)
  To: fourier.thomas
  Cc: Antoine Tenart, Herbert Xu, David S. Miller, linux-crypto, linux-kernel

IMO the patch subject could be improved, to remove the ` and to be more
descriptive. E.g.

"crypto: inside-secure: unmap DMA buffers using the original number of entries"

On Thu, Jun 19, 2025 at 05:28:36PM +0200, fourier.thomas@gmail.com wrote:
> 
> diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/inside-secure/safexcel_hash.c
> index d2b632193beb..1ef1ccfaaa95 100644
> --- a/drivers/crypto/inside-secure/safexcel_hash.c
> +++ b/drivers/crypto/inside-secure/safexcel_hash.c
> @@ -249,7 +249,10 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv,
>  	safexcel_complete(priv, ring);
>  
>  	if (sreq->nents) {
> -		dma_unmap_sg(priv->dev, areq->src, sreq->nents, DMA_TO_DEVICE);
> +		dma_unmap_sg(priv->dev,
> +			     areq->src,
> +			     sg_nents_for_len(areq->src, areq->nbytes),
> +			     DMA_TO_DEVICE);

No need to put 'areq->src,' on a new line.

>  		sreq->nents = 0;
>  	}
>  
> @@ -497,7 +500,10 @@ static int safexcel_ahash_send_req(struct crypto_async_request *async, int ring,
>  			 DMA_FROM_DEVICE);
>  unmap_sg:
>  	if (req->nents) {
> -		dma_unmap_sg(priv->dev, areq->src, req->nents, DMA_TO_DEVICE);
> +		dma_unmap_sg(priv->dev,
> +			     areq->src,
> +			     sg_nents_for_len(areq->src, areq->nbytes),
> +			     DMA_TO_DEVICE);

Same here.

Otherwise this looks good to me. With those fixed, you can add:

Reviewed-by: Antoine Tenart <atenart@kernel.org>

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-19 18:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-19 15:28 [PATCH] crypto: inside-secure: Fix `dma_unmap_sg()` nents value fourier.thomas
2025-06-19 18:10 ` Antoine Tenart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®