mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: cavium - Fix an error handling path in cpt_ucode_load_fw()
@ 2024-11-08 17:22 Christophe JAILLET
  2024-11-15 12:13 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2024-11-08 17:22 UTC (permalink / raw)
  To: George Cherian, Herbert Xu, David S. Miller, David Daney
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	George Cherian, linux-crypto

If do_cpt_init() fails, a previous dma_alloc_coherent() call needs to be
undone.

Add the needed dma_free_coherent() before returning.

Fixes: 9e2c7d99941d ("crypto: cavium - Add Support for Octeon-tx CPT Engine")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.

I guess that dmam_alloc_coherent() could also be used to fix the leak.
This would simplify cpt_unload_microcode(), IIUC.
---
 drivers/crypto/cavium/cpt/cptpf_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/cavium/cpt/cptpf_main.c b/drivers/crypto/cavium/cpt/cptpf_main.c
index ec17beee24c0..54de869e5374 100644
--- a/drivers/crypto/cavium/cpt/cptpf_main.c
+++ b/drivers/crypto/cavium/cpt/cptpf_main.c
@@ -302,6 +302,8 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae)
 
 	ret = do_cpt_init(cpt, mcode);
 	if (ret) {
+		dma_free_coherent(&cpt->pdev->dev, mcode->code_size,
+				  mcode->code, mcode->phys_base);
 		dev_err(dev, "do_cpt_init failed with ret: %d\n", ret);
 		goto fw_release;
 	}
-- 
2.47.0


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

* Re: [PATCH] crypto: cavium - Fix an error handling path in cpt_ucode_load_fw()
  2024-11-08 17:22 [PATCH] crypto: cavium - Fix an error handling path in cpt_ucode_load_fw() Christophe JAILLET
@ 2024-11-15 12:13 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2024-11-15 12:13 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: George Cherian, David S. Miller, David Daney, linux-kernel,
	kernel-janitors, George Cherian, linux-crypto

On Fri, Nov 08, 2024 at 06:22:27PM +0100, Christophe JAILLET wrote:
> If do_cpt_init() fails, a previous dma_alloc_coherent() call needs to be
> undone.
> 
> Add the needed dma_free_coherent() before returning.
> 
> Fixes: 9e2c7d99941d ("crypto: cavium - Add Support for Octeon-tx CPT Engine")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
> 
> I guess that dmam_alloc_coherent() could also be used to fix the leak.
> This would simplify cpt_unload_microcode(), IIUC.
> ---
>  drivers/crypto/cavium/cpt/cptpf_main.c | 2 ++
>  1 file changed, 2 insertions(+)

Patch applied.  Thanks.
-- 
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:[~2024-11-15 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-08 17:22 [PATCH] crypto: cavium - Fix an error handling path in cpt_ucode_load_fw() Christophe JAILLET
2024-11-15 12:13 ` Herbert Xu

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®