aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuchika Gupta <ruchika.gupta@freescale.com>2014-07-07 01:12:12 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2014-07-10 04:50:33 -0400
commit35af64038623865015d1786360cdbbcc2e72d78b (patch)
tree6cf62a6f27b022c33f9d2029692730cbba750958
parent5b635e280efce5b735042c7ffa2487c4ba8fb4bf (diff)
crypto: caam - Check for CAAM block presence before registering with crypto layer
The layer which registers with the crypto API should check for the presence of the CAAM device it is going to use. If the platform's device tree doesn't have the required CAAM node, the layer should return an error and not register the algorithms with crypto API layer. Signed-off-by: Ruchika Gupta <ruchika.gupta@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/caam/caamalg.c29
-rw-r--r--drivers/crypto/caam/caamhash.c28
-rw-r--r--drivers/crypto/caam/caamrng.c28
3 files changed, 85 insertions, 0 deletions
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 87d9de48a39e..64c606d9e821 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -2441,8 +2441,37 @@ static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template
2441 2441
2442static int __init caam_algapi_init(void) 2442static int __init caam_algapi_init(void)
2443{ 2443{
2444 struct device_node *dev_node;
2445 struct platform_device *pdev;
2446 struct device *ctrldev;
2447 void *priv;
2444 int i = 0, err = 0; 2448 int i = 0, err = 0;
2445 2449
2450 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
2451 if (!dev_node) {
2452 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
2453 if (!dev_node)
2454 return -ENODEV;
2455 }
2456
2457 pdev = of_find_device_by_node(dev_node);
2458 if (!pdev) {
2459 of_node_put(dev_node);
2460 return -ENODEV;
2461 }
2462
2463 ctrldev = &pdev->dev;
2464 priv = dev_get_drvdata(ctrldev);
2465 of_node_put(dev_node);
2466
2467 /*
2468 * If priv is NULL, it's probably because the caam driver wasn't
2469 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
2470 */
2471 if (!priv)
2472 return -ENODEV;
2473
2474
2446 INIT_LIST_HEAD(&alg_list); 2475 INIT_LIST_HEAD(&alg_list);
2447 2476
2448 /* register crypto algorithms the device supports */ 2477 /* register crypto algorithms the device supports */
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 2ab057b0a6d2..7754df4c3df1 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1793,8 +1793,36 @@ caam_hash_alloc(struct caam_hash_template *template,
1793 1793
1794static int __init caam_algapi_hash_init(void) 1794static int __init caam_algapi_hash_init(void)
1795{ 1795{
1796 struct device_node *dev_node;
1797 struct platform_device *pdev;
1798 struct device *ctrldev;
1799 void *priv;
1796 int i = 0, err = 0; 1800 int i = 0, err = 0;
1797 1801
1802 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
1803 if (!dev_node) {
1804 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
1805 if (!dev_node)
1806 return -ENODEV;
1807 }
1808
1809 pdev = of_find_device_by_node(dev_node);
1810 if (!pdev) {
1811 of_node_put(dev_node);
1812 return -ENODEV;
1813 }
1814
1815 ctrldev = &pdev->dev;
1816 priv = dev_get_drvdata(ctrldev);
1817 of_node_put(dev_node);
1818
1819 /*
1820 * If priv is NULL, it's probably because the caam driver wasn't
1821 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
1822 */
1823 if (!priv)
1824 return -ENODEV;
1825
1798 INIT_LIST_HEAD(&hash_list); 1826 INIT_LIST_HEAD(&hash_list);
1799 1827
1800 /* register crypto algorithms the device supports */ 1828 /* register crypto algorithms the device supports */
diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 8c07d3153f12..a4afa8a8ef02 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -278,6 +278,34 @@ static void __exit caam_rng_exit(void)
278static int __init caam_rng_init(void) 278static int __init caam_rng_init(void)
279{ 279{
280 struct device *dev; 280 struct device *dev;
281 struct device_node *dev_node;
282 struct platform_device *pdev;
283 struct device *ctrldev;
284 void *priv;
285
286 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
287 if (!dev_node) {
288 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
289 if (!dev_node)
290 return -ENODEV;
291 }
292
293 pdev = of_find_device_by_node(dev_node);
294 if (!pdev) {
295 of_node_put(dev_node);
296 return -ENODEV;
297 }
298
299 ctrldev = &pdev->dev;
300 priv = dev_get_drvdata(ctrldev);
301 of_node_put(dev_node);
302
303 /*
304 * If priv is NULL, it's probably because the caam driver wasn't
305 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
306 */
307 if (!priv)
308 return -ENODEV;
281 309
282 dev = caam_jr_alloc(); 310 dev = caam_jr_alloc();
283 if (IS_ERR(dev)) { 311 if (IS_ERR(dev)) {