mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: amcc: trng: use int for ppc4xx_trng_probe()
@ 2026-09-04 23:01 Rosen Penev
  0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-09-04 23:01 UTC (permalink / raw)
  To: linux-crypto; +Cc: Herbert Xu, David S. Miller, open list

Pass an error message to crypto4xx_probe() , which will allow handling
failure. The inline function returns 0 as trng is optional
functionality. Same with the of_node.

Add an extra goto in crypto4xx_probe() to unregister algs as registering
them happens before trng.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/crypto/amcc/crypto4xx_core.c |  6 +++++-
 drivers/crypto/amcc/crypto4xx_trng.c | 15 ++++++++++-----
 drivers/crypto/amcc/crypto4xx_trng.h |  6 +++---
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index a044dce65cf4..acf18b71e54d 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1315,9 +1315,13 @@ static int crypto4xx_probe(struct platform_device *ofdev)
 	if (rc)
 		goto err_irq;
 
-	ppc4xx_trng_probe(core_dev);
+	rc = ppc4xx_trng_probe(core_dev);
+	if (rc)
+		goto err_crypto;
 	return 0;
 
+err_crypto:
+	crypto4xx_unregister_alg(core_dev->dev);
 err_irq:
 	free_irq(core_dev->irq, core_dev);
 err_tasklet:
diff --git a/drivers/crypto/amcc/crypto4xx_trng.c b/drivers/crypto/amcc/crypto4xx_trng.c
index cfd66b779ce1..83e9353529fc 100644
--- a/drivers/crypto/amcc/crypto4xx_trng.c
+++ b/drivers/crypto/amcc/crypto4xx_trng.c
@@ -68,7 +68,7 @@ static const struct of_device_id ppc4xx_trng_match[] = {
 	{},
 };
 
-void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
+int ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
 {
 	struct crypto4xx_device *dev = core_dev->dev;
 	struct device_node *trng = NULL;
@@ -79,17 +79,21 @@ void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
 	trng = of_find_matching_node(NULL, ppc4xx_trng_match);
 	if (!trng || !of_device_is_available(trng)) {
 		of_node_put(trng);
-		return;
+		return 0;
 	}
 
 	dev->trng_base = of_iomap(trng, 0);
 	of_node_put(trng);
-	if (!dev->trng_base)
+	if (!dev->trng_base) {
+		err = -EINVAL;
 		goto err_out;
+	}
 
 	rng = kzalloc_obj(*rng);
-	if (!rng)
+	if (!rng) {
+		err = -ENOMEM;
 		goto err_out;
+	}
 
 	rng->name = KBUILD_MODNAME;
 	rng->data_present = ppc4xx_trng_data_present;
@@ -105,13 +109,14 @@ void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
 			err);
 		goto err_out;
 	}
-	return;
+	return 0;
 
 err_out:
 	iounmap(dev->trng_base);
 	kfree(rng);
 	dev->trng_base = NULL;
 	core_dev->trng = NULL;
+	return err;
 }
 
 void ppc4xx_trng_remove(struct crypto4xx_core_device *core_dev)
diff --git a/drivers/crypto/amcc/crypto4xx_trng.h b/drivers/crypto/amcc/crypto4xx_trng.h
index 7356716274cb..1030c3cfafd0 100644
--- a/drivers/crypto/amcc/crypto4xx_trng.h
+++ b/drivers/crypto/amcc/crypto4xx_trng.h
@@ -13,11 +13,11 @@
 #define __CRYPTO4XX_TRNG_H__
 
 #ifdef CONFIG_HW_RANDOM_PPC4XX
-void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev);
+int ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev);
 void ppc4xx_trng_remove(struct crypto4xx_core_device *core_dev);
 #else
-static inline void ppc4xx_trng_probe(
-	struct crypto4xx_core_device *dev __maybe_unused) { }
+static inline int ppc4xx_trng_probe(
+	struct crypto4xx_core_device *dev __maybe_unused) { return 0; }
 static inline void ppc4xx_trng_remove(
 	struct crypto4xx_core_device *dev __maybe_unused) { }
 #endif
-- 
2.55.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-04 23:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-04 23:01 [PATCH] crypto: amcc: trng: use int for ppc4xx_trng_probe() Rosen Penev

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®