Skip to content

Commit f0afba4

Browse files
Peijie Shaojarkkojs
authored andcommitted
tpm_tis_spi: Release chip select when flow control fails
The failure paths in tpm_tis_spi_transfer() do not deactivate chip select. Send an empty message (cs_select == 0) to overcome this. The patch is tested by two ways. One way needs to touch hardware: 1. force pull MISO pin down to GND, it emulates a forever 'WAIT' timing. 2. probe cs pin by an oscilloscope. 3. load tpm_tis_spi.ko. After loading, dmesg prints: "probe of spi0.0 failed with error -110" and oscilloscope shows cs pin goes high(deactivated) after the failure. Before the patch, cs pin keeps low. Second way is by writing a fake spi controller. 1. implement .transfer_one method, fill all rx buf with 0. 2. implement .set_cs method, print the state of cs pin. we can see cs goes high after the failure. Signed-off-by: Peijie Shao <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent edb13d7 commit f0afba4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/char/tpm/tpm_tis_spi_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
136136
}
137137

138138
exit:
139+
if (ret < 0) {
140+
/* Deactivate chip select */
141+
memset(&spi_xfer, 0, sizeof(spi_xfer));
142+
spi_message_init(&m);
143+
spi_message_add_tail(&spi_xfer, &m);
144+
spi_sync_locked(phy->spi_device, &m);
145+
}
146+
139147
spi_bus_unlock(phy->spi_device->master);
140148
return ret;
141149
}

0 commit comments

Comments
 (0)