diff mbox series

[v2,11/14] crypto: caam - free resources in case caam_rng registration failed

Message ID 1563494276-3993-12-git-send-email-iuliana.prodan@nxp.com (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series crypto: caam - fixes for kernel v5.3 | expand

Commit Message

Iuliana Prodan July 18, 2019, 11:57 p.m. UTC
Check the return value of the hardware registration for caam_rng and free
resources in case of failure.

Fixes: 6e4e603a9 ("crypto: caam - Dynamic memory allocation for caam_rng_ctx object")
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
---
 drivers/crypto/caam/caamrng.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Horia Geanta July 19, 2019, 3:53 p.m. UTC | #1
On 7/19/2019 2:58 AM, Iuliana Prodan wrote:
> Check the return value of the hardware registration for caam_rng and free
> resources in case of failure.
> 
> Fixes: 6e4e603a9 ("crypto: caam - Dynamic memory allocation for caam_rng_ctx object")
This should be:
Fixes: e24f7c9e87d4 ("crypto: caam - hwrng support")

since there are resources leaked (like DMA mapped buffers) due to not checking
the return code of hwrng_register() even in the initial caamrng commit.

This doesn't have much practical value, since we haven't seen this failure
in practice and we don't intend fixing previous kernel releases.

Horia
diff mbox series

Patch

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 561bcb5..54c32d5 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -333,7 +333,10 @@  int caam_rng_init(struct device *ctrldev)
 		goto free_rng_ctx;
 
 	dev_info(dev, "registering rng-caam\n");
-	return hwrng_register(&caam_rng);
+
+	err = hwrng_register(&caam_rng);
+	if (!err)
+		return err;
 
 free_rng_ctx:
 	kfree(rng_ctx);