Add missing NULL checks in CAAM sm
authorRadu Solea <radu.solea@nxp.com>
Wed, 8 Mar 2017 14:34:15 +0000 (16:34 +0200)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:10:54 +0000 (15:10 -0500)
    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>
drivers/crypto/caam/sm_store.c
drivers/crypto/caam/sm_test.c

index 9c41bb7..1bd921b 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * CAAM Secure Memory Storage Interface
  * Copyright (C) 2008-2015 Freescale Semiconductor, Inc.
@@ -1000,6 +999,13 @@ int caam_sm_startup(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;
+
        /*
         * Set up the private block for secure memory
         * Only one instance is possible
index d486e02..3c5eba4 100644 (file)
@@ -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)