]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tpm: call tpm_tis_wait_init() after tpm_tis_init()
authorLukas Funke <lukas.funke@weidmueller.com>
Wed, 24 Jul 2024 07:34:47 +0000 (09:34 +0200)
committerIlias Apalodimas <ilias.apalodimas@linaro.org>
Tue, 6 Aug 2024 11:01:14 +0000 (14:01 +0300)
tpm_tis_wait_init() is using the 'chip->timeout_b' field which is
initialized in tpm_tis_init(). However, the init-function is called
*after* tpm_tis_wait_init() introducing an uninitalized field access.

This commit switches both routines.

Signed-off-by: Lukas Funke <lukas.funke@weidmueller.com>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
[Ilias removed unusged 'chip' definition in tpm_tis_spi_probe()]
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Fixes: a5c30c26b28 ("tpm: Use the new API on tpm2 spi driver")
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
drivers/tpm/tpm2_tis_core.c
drivers/tpm/tpm2_tis_spi.c

index 680a6409433e8abd4cf1714a424b2da8b10a5acd..1fdf8cfa3191f73286adc2d5679f88ea801d249f 100644 (file)
@@ -419,6 +419,28 @@ static bool tis_check_ops(struct tpm_tis_phy_ops *phy_ops)
        return true;
 }
 
+static int tpm_tis_wait_init(struct udevice *dev, int loc)
+{
+       struct tpm_chip *chip = dev_get_priv(dev);
+       unsigned long start, stop;
+       u8 status;
+       int ret;
+
+       start = get_timer(0);
+       stop = chip->timeout_b;
+       do {
+               mdelay(TPM_TIMEOUT_MS);
+               ret = chip->phy_ops->read_bytes(dev, TPM_ACCESS(loc), 1, &status);
+               if (ret)
+                       break;
+
+               if (status & TPM_ACCESS_VALID)
+                       return 0;
+       } while (get_timer(start) < stop);
+
+       return -EIO;
+}
+
 int tpm_tis_init(struct udevice *dev)
 {
        struct tpm_chip *chip = dev_get_priv(dev);
@@ -436,6 +458,12 @@ int tpm_tis_init(struct udevice *dev)
        chip->timeout_c = TIS_SHORT_TIMEOUT_MS;
        chip->timeout_d = TIS_SHORT_TIMEOUT_MS;
 
+       ret = tpm_tis_wait_init(dev, chip->locality);
+       if (ret) {
+               log(LOGC_DM, LOGL_ERR, "%s: no device found\n", __func__);
+               return ret;
+       }
+
        ret = tpm_tis_request_locality(dev, 0);
        if (ret)
                return ret;
index d35a4dd3a364408c7802ff3aabc4b40b61f3c082..c433e8088aca8d2fb5cca9ec819fc732905b1e99 100644 (file)
@@ -187,29 +187,6 @@ static int tpm_tis_spi_write32(struct udevice *dev, u32 addr, u32 value)
        return tpm_tis_spi_write(dev, addr, sizeof(value), (u8 *)&value_le);
 }
 
-static int tpm_tis_wait_init(struct udevice *dev, int loc)
-{
-       struct tpm_chip *chip = dev_get_priv(dev);
-       unsigned long start, stop;
-       u8 status;
-       int ret;
-
-       start = get_timer(0);
-       stop = chip->timeout_b;
-       do {
-               mdelay(TPM_TIMEOUT_MS);
-
-               ret = tpm_tis_spi_read(dev, TPM_ACCESS(loc), 1, &status);
-               if (ret)
-                       break;
-
-               if (status & TPM_ACCESS_VALID)
-                       return 0;
-       } while (get_timer(start) < stop);
-
-       return -EIO;
-}
-
 static struct tpm_tis_phy_ops phy_ops = {
        .read_bytes = tpm_tis_spi_read,
        .write_bytes = tpm_tis_spi_write,
@@ -221,7 +198,6 @@ static int tpm_tis_spi_probe(struct udevice *dev)
 {
        struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
        struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
-       struct tpm_chip *chip = dev_get_priv(dev);
        int ret;
 
        /* Use the TPM v2 stack */
@@ -255,12 +231,6 @@ static int tpm_tis_spi_probe(struct udevice *dev)
        /* Ensure a minimum amount of time elapsed since reset of the TPM */
        mdelay(drv_data->time_before_first_cmd_ms);
 
-       ret = tpm_tis_wait_init(dev, chip->locality);
-       if (ret) {
-               log(LOGC_DM, LOGL_ERR, "%s: no device found\n", __func__);
-               return ret;
-       }
-
        tpm_tis_ops_register(dev, &phy_ops);
        ret = tpm_tis_init(dev);
        if (ret)