[U-Boot] [PATCH v2 1/2] tpm: Fix fault in case CONFIG_DM_TPM is set without any TPM

Christophe Ricard christophe.ricard at gmail.com
Thu Jan 21 23:19:13 CET 2016


In case CONFIG_DM_TPM was set without any TPM chipset configured a fault
was generated (NULL pointer access).

Reviewed-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Christophe Ricard <christophe-h.ricard at st.com>
---

Changes in v2:
- Adding Reviewed-by: Simon Glass <sjg at chromium.org>

 common/cmd_tpm.c | 2 +-
 lib/tpm.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index add6bfb..6edf3e9 100644
--- a/common/cmd_tpm.c
+++ b/common/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;
 	}
diff --git a/lib/tpm.c b/lib/tpm.c
index 8a62216..f428d45 100644
--- 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);
 }
-- 
2.5.0



More information about the U-Boot mailing list