Skip to content

Commit a86c4c6

Browse files
committed
tpm_tis: Explicitly check for error code
JIRA: https://issues.redhat.com/browse/RHEL-72765 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git Conflicts: Missing line due to missing f25534a. commit 513253f Author: Alexander Steffen <Alexander.Steffen@infineon.com> Date: Tue Jun 13 20:02:56 2023 +0200 tpm_tis: Explicitly check for error code recv_data either returns the number of received bytes, or a negative value representing an error code. Adding the return value directly to the total number of received bytes therefore looks a little weird, since it might add a negative error code to a sum of bytes. The following check for size < expected usually makes the function return ETIME in that case, so it does not cause too many problems in practice. But to make the code look cleaner and because the caller might still be interested in the original error code, explicitly check for the presence of an error code and pass that through. Cc: stable@vger.kernel.org Fixes: cb53542 ("[PATCH] tpm: spacing cleanups 2") 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: Štěpán Horáček <shoracek@redhat.com>
1 parent 30e2b2c commit a86c4c6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/char/tpm/tpm_tis_core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
343343
int size = 0;
344344
int status;
345345
u32 expected;
346+
int rc;
346347

347348
if (count < TPM_HEADER_SIZE) {
348349
size = -EIO;
@@ -362,8 +363,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
362363
goto out;
363364
}
364365

365-
size += recv_data(chip, &buf[TPM_HEADER_SIZE],
366-
expected - TPM_HEADER_SIZE);
366+
rc = recv_data(chip, &buf[TPM_HEADER_SIZE],
367+
expected - TPM_HEADER_SIZE);
368+
if (rc < 0) {
369+
size = rc;
370+
goto out;
371+
}
372+
size += rc;
367373
if (size < expected) {
368374
dev_err(&chip->dev, "Unable to read remainder of result\n");
369375
size = -ETIME;

0 commit comments

Comments
 (0)