pci: Make Rockchip PCIe voltage regulators optional
[oweals/u-boot.git] / drivers / tpm / tpm_tis_st33zp24_spi.c
index dcf55ee03af8dedb05cefff24344bbe6a5ac0b79..ef54e3b7b293077daa62c344fec321356bd95569 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * STMicroelectronics TPM ST33ZP24 SPI UBOOT driver
  *
  * This device driver implements the TPM interface as defined in
  * the TCG TPM Interface Spec version 1.21, revision 1.0 and the
  * STMicroelectronics Protocol Stack Specification version 1.2.0.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <dm.h>
 #include <fdtdec.h>
+#include <log.h>
 #include <spi.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 #include <errno.h>
+#include <linux/delay.h>
 #include <linux/types.h>
 #include <asm/unaligned.h>
 #include <linux/compat.h>
@@ -431,7 +432,8 @@ static int st33zp24_spi_recv_data(struct udevice *dev, u8 *buf, size_t count)
 static int st33zp24_spi_recv(struct udevice *dev, u8 *buf, size_t count)
 {
        struct tpm_chip *chip = dev_get_priv(dev);
-       int size, expected;
+       int size;
+       unsigned int expected;
 
        if (!chip)
                return -ENODEV;
@@ -448,7 +450,7 @@ static int st33zp24_spi_recv(struct udevice *dev, u8 *buf, size_t count)
        }
 
        expected = get_unaligned_be32(buf + 2);
-       if (expected > count) {
+       if (expected > count || expected < TPM_HEADER_SIZE) {
                size = -EIO;
                goto out;
        }