[RESEND,2/2] crypto: caam - Support deferred probing in JR dependent drivers
diff mbox series

Message ID 20180807080026.17039-3-m.niestroj@grinn-global.com
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series
  • crypto: caam - Support deferred probing of JR dependend drivers
Related show

Commit Message

Marcin Niestrój Aug. 7, 2018, 8 a.m. UTC
It is possible, that caam_jr_alloc() is called before JR devices are
probed. Return -EPROBE_DEFER in drivers that rely on JR devices, so
they are probed at later stage.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
---
 drivers/crypto/caam/caamalg.c    | 3 +++
 drivers/crypto/caam/caamalg_qi.c | 3 +++
 drivers/crypto/caam/caamhash.c   | 3 +++
 drivers/crypto/caam/caampkc.c    | 3 +++
 drivers/crypto/caam/caamrng.c    | 3 +++
 5 files changed, 15 insertions(+)

Comments

Horia Geanta Aug. 7, 2018, 12:34 p.m. UTC | #1
On 8/7/2018 11:00 AM, Marcin Niestroj wrote:
> It is possible, that caam_jr_alloc() is called before JR devices are
> probed. Return -EPROBE_DEFER in drivers that rely on JR devices, so
> they are probed at later stage.
> 
These drivers don't have a probe() callback.
Returning -EPROBE_DEFER in module's init() (caamrng) or crypto algorithm's
init() (caamalg etc.) callbacks is not going to help, they won't be called later.

Does adding request_module("caam_jr") in module's init() solve the issue?

Regards,
Horia
Herbert Xu Aug. 25, 2018, 11:33 a.m. UTC | #2
On Tue, Aug 07, 2018 at 12:34:57PM +0000, Horia Geanta wrote:
> On 8/7/2018 11:00 AM, Marcin Niestroj wrote:
> > It is possible, that caam_jr_alloc() is called before JR devices are
> > probed. Return -EPROBE_DEFER in drivers that rely on JR devices, so
> > they are probed at later stage.
> > 
> These drivers don't have a probe() callback.
> Returning -EPROBE_DEFER in module's init() (caamrng) or crypto algorithm's
> init() (caamalg etc.) callbacks is not going to help, they won't be called later.
> 
> Does adding request_module("caam_jr") in module's init() solve the issue?

If everything is built as a module this should always work because
a module isn't available until after its init function has finished.

So the only problem here appears to be when everything is built-in
in which case the init functions are run in random order.

So perhaps move caam_jr's module_init function to an earlier level
(i.e., earlier than device_initcall)?

Cheers,

Patch
diff mbox series

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index d67667970f7e..610a3f72ac5d 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -3253,6 +3253,9 @@  static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
 
 	ctx->jrdev = caam_jr_alloc();
 	if (IS_ERR(ctx->jrdev)) {
+		if (PTR_ERR(ctx->jrdev))
+			return -EPROBE_DEFER;
+
 		pr_err("Job Ring Device allocation for transform failed\n");
 		return PTR_ERR(ctx->jrdev);
 	}
diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c
index 6e61cc93c2b0..85c69a8b5126 100644
--- a/drivers/crypto/caam/caamalg_qi.c
+++ b/drivers/crypto/caam/caamalg_qi.c
@@ -2547,6 +2547,9 @@  static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
 	 */
 	ctx->jrdev = caam_jr_alloc();
 	if (IS_ERR(ctx->jrdev)) {
+		if (PTR_ERR(ctx->jrdev))
+			return -EPROBE_DEFER;
+
 		pr_err("Job Ring Device allocation for transform failed\n");
 		return PTR_ERR(ctx->jrdev);
 	}
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 0beb28196e20..c2ccb802b7d5 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1746,6 +1746,9 @@  static int caam_hash_cra_init(struct crypto_tfm *tfm)
 	 */
 	ctx->jrdev = caam_jr_alloc();
 	if (IS_ERR(ctx->jrdev)) {
+		if (PTR_ERR(ctx->jrdev))
+			return -EPROBE_DEFER;
+
 		pr_err("Job Ring Device allocation for transform failed\n");
 		return PTR_ERR(ctx->jrdev);
 	}
diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 578ea63a3109..072da03207a1 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -972,6 +972,9 @@  static int caam_rsa_init_tfm(struct crypto_akcipher *tfm)
 	ctx->dev = caam_jr_alloc();
 
 	if (IS_ERR(ctx->dev)) {
+		if (PTR_ERR(ctx->dev))
+			return -EPROBE_DEFER;
+
 		pr_err("Job Ring Device allocation for transform failed\n");
 		return PTR_ERR(ctx->dev);
 	}
diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index fde07d4ff019..56616b94416b 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -340,6 +340,9 @@  static int __init caam_rng_init(void)
 
 	dev = caam_jr_alloc();
 	if (IS_ERR(dev)) {
+		if (PTR_ERR(dev))
+			return -EPROBE_DEFER;
+
 		pr_err("Job Ring Device allocation for transform failed\n");
 		return PTR_ERR(dev);
 	}