Skip to content

Commit eac9347

Browse files
diandersJarkko Sakkinen
authored andcommitted
tpm_tis_spi: Don't send anything during flow control
During flow control we are just reading from the TPM, yet our spi_xfer has the tx_buf and rx_buf both non-NULL which means we're requesting a full duplex transfer. SPI is always somewhat of a full duplex protocol anyway and in theory the other side shouldn't really be looking at what we're sending it during flow control, but it's still a bit ugly to be sending some "random" data when we shouldn't. The default tpm_tis_spi_flow_control() tries to address this by setting 'phy->iobuf[0] = 0'. This partially avoids the problem of sending "random" data, but since our tx_buf and rx_buf both point to the same place I believe there is the potential of us sending the TPM's previous byte back to it if we hit the retry loop. Another flow control implementation, cr50_spi_flow_control(), doesn't address this at all. Let's clean this up and just make the tx_buf NULL before we call flow_control(). Not only does this ensure that we're not sending any "random" bytes but it also possibly could make the SPI controller behave in a slightly more optimal way. NOTE: no actual observed problems are fixed by this patch--it's was just made based on code inspection. Signed-off-by: Douglas Anderson <[email protected]> Reviewed-by: Paul Menzel <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 7862840 commit eac9347

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/char/tpm/tpm_tis_spi_main.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy,
5353

5454
if ((phy->iobuf[3] & 0x01) == 0) {
5555
// handle SPI wait states
56-
phy->iobuf[0] = 0;
57-
5856
for (i = 0; i < TPM_RETRY; i++) {
5957
spi_xfer->len = 1;
6058
spi_message_init(&m);
@@ -104,6 +102,8 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
104102
if (ret < 0)
105103
goto exit;
106104

105+
/* Flow control transfers are receive only */
106+
spi_xfer.tx_buf = NULL;
107107
ret = phy->flow_control(phy, &spi_xfer);
108108
if (ret < 0)
109109
goto exit;
@@ -113,9 +113,8 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
113113
spi_xfer.delay.value = 5;
114114
spi_xfer.delay.unit = SPI_DELAY_UNIT_USECS;
115115

116-
if (in) {
117-
spi_xfer.tx_buf = NULL;
118-
} else if (out) {
116+
if (out) {
117+
spi_xfer.tx_buf = phy->iobuf;
119118
spi_xfer.rx_buf = NULL;
120119
memcpy(phy->iobuf, out, transfer_len);
121120
out += transfer_len;

0 commit comments

Comments
 (0)