diff mbox

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

Message ID 1453414754-10647-2-git-send-email-christophe-h.ricard@st.com
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Christophe Ricard Jan. 21, 2016, 10:19 p.m. UTC
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>
---

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

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

Comments

Simon Glass Jan. 22, 2016, 3:02 a.m. UTC | #1
On 21 January 2016 at 15:19, Christophe Ricard
<christophe.ricard@gmail.com> wrote:
> 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>
> ---
>
> Changes in v2:
> - Adding Reviewed-by: Simon Glass <sjg@chromium.org>
>
>  common/cmd_tpm.c | 2 +-
>  lib/tpm.c        | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox

Patch

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);
 }