summaryrefslogtreecommitdiff
path: root/drivers/crypto/caam
diff options
context:
space:
mode:
authorRadu Solea <radu.solea@nxp.com>2017-03-08 16:34:15 +0200
committerLeonard Crestez <leonard.crestez@nxp.com>2018-08-24 12:41:33 +0300
commit9dc910187c094c1846a19291ca38504fe1209a2b (patch)
tree46d8bc2bdaae2f6dff1caee03011c91e95914b74 /drivers/crypto/caam
parent2ce41376605003026929dbc8f6260ad1eff186b3 (diff)
Add missing NULL checks in CAAM sm
Missing NULL checks in CAAM sm_store and sm_test cause kernel crashes if caam init fails. Signed-off-by: Radu Solea <radu.solea@nxp.com>
Diffstat (limited to 'drivers/crypto/caam')
-rw-r--r--drivers/crypto/caam/sm_store.c8
-rw-r--r--drivers/crypto/caam/sm_test.c9
2 files changed, 15 insertions, 2 deletions
diff --git a/drivers/crypto/caam/sm_store.c b/drivers/crypto/caam/sm_store.c
index 9c41bb71fecf..1bd921be59bc 100644
--- a/drivers/crypto/caam/sm_store.c
+++ b/drivers/crypto/caam/sm_store.c
@@ -1,4 +1,3 @@
-
/*
* CAAM Secure Memory Storage Interface
* Copyright (C) 2008-2015 Freescale Semiconductor, Inc.
@@ -1001,6 +1000,13 @@ int caam_sm_startup(struct platform_device *pdev)
ctrlpriv = dev_get_drvdata(ctrldev);
/*
+ * If ctrlpriv is NULL, it's probably because the caam driver wasn't
+ * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
+ */
+ if (!ctrlpriv)
+ return -ENODEV;
+
+ /*
* Set up the private block for secure memory
* Only one instance is possible
*/
diff --git a/drivers/crypto/caam/sm_test.c b/drivers/crypto/caam/sm_test.c
index d486e0277825..3c5eba4c6fbc 100644
--- a/drivers/crypto/caam/sm_test.c
+++ b/drivers/crypto/caam/sm_test.c
@@ -1,4 +1,3 @@
-
/*
* Secure Memory / Keystore Exemplification Module
* Copyright (C) 2012-2015 Freescale Semiconductor, Inc. All Rights Reserved
@@ -105,6 +104,14 @@ int caam_sm_example_init(struct platform_device *pdev)
*/
ctrldev = &pdev->dev;
ctrlpriv = dev_get_drvdata(ctrldev);
+
+ /*
+ * If ctrlpriv is NULL, it's probably because the caam driver wasn't
+ * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
+ */
+ if (!ctrlpriv)
+ return -ENODEV;
+
ksdev = ctrlpriv->smdev;
kspriv = dev_get_drvdata(ksdev);
if (kspriv == NULL)