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 <[email protected]> --- drivers/char/tpm/tpm-interface.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 0a79ed3696b7..021553e8a314 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -630,7 +630,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; @@ -656,8 +655,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; @@ -667,7 +670,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; -- 2.39.5
