tpm: In tpm_get_random() replace 'retries' with a zero check
Check for zero byte read instead of having retries counter in order to make
wait flag properly enforcing. Progress is still guaranteed given the zero
check and iterations are capped up to TPM_MAX_RNG_DATA iterations at most
(as per theoretical limit).
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 5cc2bba..594ad09 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -620,7 +620,6 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max, bool wait)
{
u32 num_bytes = max;
u8 *out_ptr = out;
- int retries = 5;
int total = 0;
int rc;
@@ -646,8 +645,12 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max, bool wait)
else
rc = tpm1_get_random(chip, out_ptr, num_bytes);
- if (rc < 0)
+ if (rc <= 0) {
+ if (!rc)
+ rc = -EIO;
+
goto err;
+ }
if (!wait) {
total = rc;
@@ -657,7 +660,7 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max, bool wait)
out_ptr += rc;
total += rc;
num_bytes -= rc;
- } while (retries-- && total < max);
+ } while (total < max);
tpm_put_ops(chip);
return total ? total : -EIO;