summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2017-03-27 16:20:17 -0500
committerAaron Durbin <adurbin@chromium.org>2017-04-03 05:33:27 +0200
commit92190198b04413a732d2f838be771ea032cd1d27 (patch)
tree531e92a25af5569adefb73fcc8d555e4b383ab88 /src/drivers
parent9b8784475c2ea5efedc59d199f95c816f282a19f (diff)
drivers/i2c/tpm: remove 1260 byte buffer from stack
The tis.c module is needlessly copying data to/from a 1260 byte buffer on the stack. Each device's transport implementation (cr50.c or tpm.c) maintains its own buffer, if needed, for framing purposes. Therefore, remove the duplicated buffer. BUG=b:36598499 Change-Id: I478fb57cb65509b5d74bdd871f1a231f8080bc2f Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/19061 Reviewed-by: Furquan Shaikh <furquan@google.com> Tested-by: build bot (Jenkins)
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/i2c/tpm/tis.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/drivers/i2c/tpm/tis.c b/src/drivers/i2c/tpm/tis.c
index d61cadac30..9bdf0130e2 100644
--- a/src/drivers/i2c/tpm/tis.c
+++ b/src/drivers/i2c/tpm/tis.c
@@ -73,13 +73,14 @@ int tis_init(void)
CONFIG_DRIVER_TPM_I2C_ADDR);
}
-static ssize_t tpm_transmit(const uint8_t *buf, size_t bufsiz)
+static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf,
+ size_t rbufsiz)
{
int rc;
uint32_t count;
struct tpm_chip *chip = car_get_var_ptr(&g_chip);
- memcpy(&count, buf + TPM_CMD_COUNT_BYTE, sizeof(count));
+ memcpy(&count, sbuf + TPM_CMD_COUNT_BYTE, sizeof(count));
count = be32_to_cpu(count);
if (!chip->vendor.send || !chip->vendor.status || !chip->vendor.cancel)
@@ -89,14 +90,14 @@ static ssize_t tpm_transmit(const uint8_t *buf, size_t bufsiz)
printk(BIOS_DEBUG, "tpm_transmit: no data\n");
return -1;
}
- if (count > bufsiz) {
+ if (count > sbufsiz) {
printk(BIOS_DEBUG, "tpm_transmit: invalid count value %x %zx\n",
- count, bufsiz);
+ count, sbufsiz);
return -1;
}
ASSERT(chip->vendor.send);
- rc = chip->vendor.send(chip, (uint8_t *) buf, count);
+ rc = chip->vendor.send(chip, (uint8_t *) sbuf, count);
if (rc < 0) {
printk(BIOS_DEBUG, "tpm_transmit: tpm_send error\n");
goto out;
@@ -132,7 +133,7 @@ static ssize_t tpm_transmit(const uint8_t *buf, size_t bufsiz)
out_recv:
- rc = chip->vendor.recv(chip, (uint8_t *) buf, TPM_BUFSIZE);
+ rc = chip->vendor.recv(chip, (uint8_t *) rbuf, rbufsiz);
if (rc < 0)
printk(BIOS_DEBUG, "tpm_transmit: tpm_recv: error %d\n", rc);
out:
@@ -142,11 +143,7 @@ out:
int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
uint8_t *recvbuf, size_t *rbuf_len)
{
- uint8_t buf[TPM_BUFSIZE];
-
ASSERT(sbuf_size >= 10);
- if (sizeof(buf) < sbuf_size)
- return -1;
/* Display the TPM command */
if (IS_ENABLED(CONFIG_DRIVER_TPM_DISPLAY_TIS_BYTES)) {
@@ -156,8 +153,7 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
hexdump(sendbuf, sbuf_size);
}
- memcpy(buf, sendbuf, sbuf_size);
- int len = tpm_transmit(buf, sbuf_size);
+ int len = tpm_transmit(sendbuf, sbuf_size, recvbuf, *rbuf_len);
if (len < 10) {
*rbuf_len = 0;
@@ -169,7 +165,6 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
return -1;
}
- memcpy(recvbuf, buf, len);
*rbuf_len = len;
/* Display the TPM response */