diff mbox

[v2] tpm/tpm_i2c_stm_st33: Add proper wait for ordinal duration in case of irq mode

Message ID 1427048520-18651-2-git-send-email-christophe-h.ricard@st.com (mailing list archive)
State New, archived
Headers show

Commit Message

Christophe Ricard March 22, 2015, 6:22 p.m. UTC
In case the driver is configured to use irq, we are not waiting the answer
for a duration period to see the DATA_AVAIL status bit to raise but at
maximum timeout_c. This may result in critical failure as we will
not wait long enough for the command completion.

This patch is a backport from kernel 4.1 fix.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
---
 drivers/char/tpm/tpm_i2c_stm_st33.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.c b/drivers/char/tpm/tpm_i2c_stm_st33.c
index 612845b..00362ea 100644
--- a/drivers/char/tpm/tpm_i2c_stm_st33.c
+++ b/drivers/char/tpm/tpm_i2c_stm_st33.c
@@ -496,7 +496,7 @@  static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
 static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
 			    size_t len)
 {
-	u32 status, i, size;
+	u32 status, i, size, ordinal;
 	int burstcnt = 0;
 	int ret;
 	u8 data;
@@ -559,6 +559,17 @@  static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
 	data = TPM_STS_GO;
 	I2C_WRITE_DATA(tpm_dev, TPM_STS, &data, 1);
 
+	if (chip->vendor.irq) {
+		ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
+
+		if (wait_for_stat(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
+				  tpm_calc_ordinal_duration(chip, ordinal),
+				  &chip->vendor.read_queue, true) < 0) {
+			ret = -ETIME;
+			goto out_err;
+		}
+	}
+
 	return len;
 out_err:
 	tpm_stm_i2c_cancel(chip);