tpm: Fix fault in case CONFIG_DM_TPM is set without any TPM
authorChristophe Ricard <christophe.ricard@gmail.com>
Thu, 21 Jan 2016 22:19:13 +0000 (23:19 +0100)
committerSimon Glass <sjg@chromium.org>
Fri, 29 Jan 2016 04:01:22 +0000 (21:01 -0700)
In case CONFIG_DM_TPM was set without any TPM chipset configured a fault
was generated (NULL pointer access).

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
cmd/tpm.c
lib/tpm.c

index add6bfb416e0ca7966652775acd684e50ac3e750..6edf3e9dc35de128f7a8dfa221da824d1979846a 100644 (file)
--- a/cmd/tpm.c
+++ b/cmd/tpm.c
@@ -448,7 +448,7 @@ static int get_tpm(struct udevice **devp)
        int rc;
 
        rc = uclass_first_device(UCLASS_TPM, devp);
-       if (rc) {
+       if (rc || !*devp) {
                printf("Could not find TPM (ret=%d)\n", rc);
                return CMD_RET_FAILURE;
        }
index 8a622162740f9863b76b2cddfc80dee4886c1c7a..f428d454fbece41d01ca4610cc2201e5f0716502 100644 (file)
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -262,7 +262,7 @@ int tpm_init(void)
        struct udevice *dev;
 
        err = uclass_first_device(UCLASS_TPM, &dev);
-       if (err)
+       if (err || !dev)
                return err;
        return tpm_open(dev);
 }