All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] crypto: octeontx2 - Use dma_alloc_noncoherent() instead of kzalloc/dma_map_single()
@ 2021-10-12  3:22 Cai Huoqing
  2021-10-22 12:11 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Cai Huoqing @ 2021-10-12  3:22 UTC (permalink / raw)
  To: hch
  Cc: Cai Huoqing, Boris Brezillon, Arnaud Ebalard, Srujana Challa,
	Herbert Xu, David S. Miller, linux-crypto, linux-kernel

Replacing kzalloc/kfree/dma_map_single/dma_unmap_single()
with dma_alloc_noncoherent/dma_free_noncoherent() helps to
reduce code size, and simplify the code, and the hardware
can keep DMA coherent itself.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
v1->v2:
	*Change to dma_alloc/free_noncoherent from dma_alloc/free_coherent.
	*Update changelog.

 drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c b/drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c
index dff34b3ec09e..f023a02ee2b5 100644
--- a/drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c
+++ b/drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c
@@ -1449,18 +1449,11 @@ int otx2_cpt_discover_eng_capabilities(struct otx2_cptpf_dev *cptpf)
 	compl_rlen = ALIGN(sizeof(union otx2_cpt_res_s), OTX2_CPT_DMA_MINALIGN);
 	len = compl_rlen + LOADFVC_RLEN;
 
-	result = kzalloc(len, GFP_KERNEL);
+	result = dma_alloc_noncoherent(&pdev->dev, len, &rptr_baddr, DMA_BIDIRECTIONAL, GFP_KERNEL);
 	if (!result) {
 		ret = -ENOMEM;
 		goto lf_cleanup;
 	}
-	rptr_baddr = dma_map_single(&pdev->dev, (void *)result, len,
-				    DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(&pdev->dev, rptr_baddr)) {
-		dev_err(&pdev->dev, "DMA mapping failed\n");
-		ret = -EFAULT;
-		goto free_result;
-	}
 	rptr = (u8 *)result + compl_rlen;
 
 	/* Fill in the command */
@@ -1489,11 +1482,9 @@ int otx2_cpt_discover_eng_capabilities(struct otx2_cptpf_dev *cptpf)
 
 		cptpf->eng_caps[etype].u = be64_to_cpup(rptr);
 	}
-	dma_unmap_single(&pdev->dev, rptr_baddr, len, DMA_BIDIRECTIONAL);
+	dma_free_noncoherent(&pdev->dev, len, (void *)result, rptr_baddr, DMA_BIDIRECTIONAL);
 	cptpf->is_eng_caps_discovered = true;
 
-free_result:
-	kfree(result);
 lf_cleanup:
 	otx2_cptlf_shutdown(&cptpf->lfs);
 delete_grps:
-- 
2.25.1


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

* Re: [PATCH v2] crypto: octeontx2 - Use dma_alloc_noncoherent() instead of kzalloc/dma_map_single()
  2021-10-12  3:22 [PATCH v2] crypto: octeontx2 - Use dma_alloc_noncoherent() instead of kzalloc/dma_map_single() Cai Huoqing
@ 2021-10-22 12:11 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2021-10-22 12:11 UTC (permalink / raw)
  To: Cai Huoqing
  Cc: hch, caihuoqing, bbrezillon, arno, schalla, davem, linux-crypto,
	linux-kernel

Cai Huoqing <caihuoqing@baidu.com> wrote:
>
> @@ -1489,11 +1482,9 @@ int otx2_cpt_discover_eng_capabilities(struct otx2_cptpf_dev *cptpf)
> 
>                cptpf->eng_caps[etype].u = be64_to_cpup(rptr);
>        }
> -       dma_unmap_single(&pdev->dev, rptr_baddr, len, DMA_BIDIRECTIONAL);
> +       dma_free_noncoherent(&pdev->dev, len, (void *)result, rptr_baddr, DMA_BIDIRECTIONAL);

Why the cast?

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2021-10-22 12:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12  3:22 [PATCH v2] crypto: octeontx2 - Use dma_alloc_noncoherent() instead of kzalloc/dma_map_single() Cai Huoqing
2021-10-22 12:11 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.