[PATCH v2] tpm_tis_spi: fix:release chip select when flow control fails
From: shaopeijie
Date: Mon May 22 2023 - 03:14:21 EST
From: Peijie Shao <shaopeijie@xxxxxxxx>
The failure paths in tpm_tis_spi_transfer() do not deactivate
chip select. Send an empty message (cs_select == 0) to overcome
this.
Signed-off-by: Peijie Shao <shaopeijie@xxxxxxxx>
---
Changes since v1:
1. Deactive cs all of the failure path, not only flow control.
2. change and update comments.
---
drivers/char/tpm/tpm_tis_spi_main.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c
index 1f5207974..9bfaba092 100644
--- a/drivers/char/tpm/tpm_tis_spi_main.c
+++ b/drivers/char/tpm/tpm_tis_spi_main.c
@@ -136,6 +136,14 @@ int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
}
exit:
+ if (ret < 0) {
+ /* Deactivate chip select */
+ memset(&spi_xfer, 0, sizeof(spi_xfer));
+ spi_message_init(&m);
+ spi_message_add_tail(&spi_xfer, &m);
+ spi_sync_locked(phy->spi_device, &m);
+ }
+
spi_bus_unlock(phy->spi_device->master);
return ret;
}
--
2.39.1