Skip to content

Commit

Permalink
crypto: caam - fix hash, alg and rng registration if CAAM driver not …
Browse files Browse the repository at this point in the history
…initialized

If the CAAM driver initialization failed (due to various reasons, e.g. RNG4
initialization failed), then the registration of hash/algorithms/rng shouldn't
take place. This patch adds the necessary code to prevent this registration.

Signed-off-by: Alex Porosanu <alexandru.porosanu@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Alex Porosanu authored and Herbert Xu committed Sep 13, 2013
1 parent d5e4e99 commit b2744df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/crypto/caam/caamalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,13 @@ static int __init caam_algapi_init(void)
priv = dev_get_drvdata(ctrldev);
of_node_put(dev_node);

/*
* If priv is NULL, it's probably because the caam driver wasn't
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
*/
if (!priv)
return -ENODEV;

INIT_LIST_HEAD(&priv->alg_list);

atomic_set(&priv->tfm_count, -1);
Expand Down
7 changes: 7 additions & 0 deletions drivers/crypto/caam/caamhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,13 @@ static int __init caam_algapi_hash_init(void)
priv = dev_get_drvdata(ctrldev);
of_node_put(dev_node);

/*
* If priv is NULL, it's probably because the caam driver wasn't
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
*/
if (!priv)
return -ENODEV;

INIT_LIST_HEAD(&priv->hash_list);

atomic_set(&priv->tfm_count, -1);
Expand Down
7 changes: 7 additions & 0 deletions drivers/crypto/caam/caamrng.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ static int __init caam_rng_init(void)
priv = dev_get_drvdata(ctrldev);
of_node_put(dev_node);

/*
* If priv is NULL, it's probably because the caam driver wasn't
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
*/
if (!priv)
return -ENODEV;

caam_init_rng(&rng_ctx, priv->jrdev[0]);

dev_info(priv->jrdev[0], "registering rng-caam\n");
Expand Down

0 comments on commit b2744df

Please sign in to comment.