2021-02-28 09:34:35

by Dinghao Liu

[permalink] [raw]
Subject: [PATCH] tpm: Add missing check in tpm_inf_recv

The use of wait() in tpm_inf_recv() is almost the same. It's odd that
we only check the return value and terminate execution flow of one call.

Signed-off-by: Dinghao Liu <[email protected]>
---
drivers/char/tpm/tpm_infineon.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index 9c924a1440a9..abe00f45aa45 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -263,7 +263,9 @@ static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count)
size = ((buf[2] << 8) | buf[3]);

for (i = 0; i < size; i++) {
- wait(chip, STAT_RDA);
+ ret = wait(chip, STAT_RDA);
+ if (ret)
+ return -EIO;
buf[i] = tpm_data_in(RDFIFO);
}

--
2.17.1


2021-03-03 01:50:21

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH] tpm: Add missing check in tpm_inf_recv

On Sun, Feb 28, 2021 at 05:32:30PM +0800, Dinghao Liu wrote:
> The use of wait() in tpm_inf_recv() is almost the same. It's odd that
> we only check the return value and terminate execution flow of one call.
>
> Signed-off-by: Dinghao Liu <[email protected]>

Is the unchecked return value of wait() the problem? I don't see the
function even mentioned in the description.

/Jarkko

> ---
> drivers/char/tpm/tpm_infineon.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
> index 9c924a1440a9..abe00f45aa45 100644
> --- a/drivers/char/tpm/tpm_infineon.c
> +++ b/drivers/char/tpm/tpm_infineon.c
> @@ -263,7 +263,9 @@ static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count)
> size = ((buf[2] << 8) | buf[3]);
>
> for (i = 0; i < size; i++) {
> - wait(chip, STAT_RDA);
> + ret = wait(chip, STAT_RDA);
> + if (ret)
> + return -EIO;
> buf[i] = tpm_data_in(RDFIFO);
> }
>
> --
> 2.17.1
>
>