]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tpm_tis: Resend command to recover from data transfer errors
authorAlexander Steffen <Alexander.Steffen@infineon.com>
Tue, 13 Jun 2023 18:02:59 +0000 (20:02 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Sep 2023 09:11:02 +0000 (11:11 +0200)
[ Upstream commit 280db21e153d8810ce3b93640c63ae922bcb9e8e ]

Similar to the transmission of TPM responses, also the transmission of TPM
commands may become corrupted. Instead of aborting when detecting such
issues, try resending the command again.

Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/char/tpm/tpm_tis_core.c

index 44f71f2c8cfa014ae2400c839bc508aa63b780f7..5889d9edaf94062e0bfb5f22fd2f5178b6861a59 100644 (file)
@@ -498,10 +498,17 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
        int rc;
        u32 ordinal;
        unsigned long dur;
+       unsigned int try;
 
-       rc = tpm_tis_send_data(chip, buf, len);
-       if (rc < 0)
-               return rc;
+       for (try = 0; try < TPM_RETRY; try++) {
+               rc = tpm_tis_send_data(chip, buf, len);
+               if (rc >= 0)
+                       /* Data transfer done successfully */
+                       break;
+               else if (rc != -EIO)
+                       /* Data transfer failed, not recoverable */
+                       return rc;
+       }
 
        rc = tpm_tis_verify_crc(priv, len, buf);
        if (rc < 0) {