All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tpm: tpm_try_transmit() refactor error flow.
@ 2018-10-16 13:37 Tomas Winkler
  2018-10-18  0:14 ` Jarkko Sakkinen
  0 siblings, 1 reply; 16+ messages in thread
From: Tomas Winkler @ 2018-10-16 13:37 UTC (permalink / raw)
  To: Jarkko Sakkinen, Jason Gunthorpe
  Cc: Nayna Jain, Alexander Usyskin, Tadeusz Struk, linux-integrity,
	linux-security-module, linux-kernel, Tomas Winkler, stable

First, rename out_no_locality to out_locality for bailing out on
both tpm_cmd_ready() and tpm_request_locality() failure.
Second, ignore the return value of go_to_idle() as  it may override
the return value of the actual tpm operation, the go_to_idle() error
will be caught on any consequent command.
Last, fix the wrong 'goto out', that jumped back instead of forward.

Cc: stable@vger.kernel.org
Fixes: 627448e85c76 ("tpm: separate cmd_ready/go_idle from runtime_pm")
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
---
 drivers/char/tpm/tpm-interface.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 129f640424b7..95db630dd722 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -477,13 +477,15 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
 
 	if (need_locality) {
 		rc = tpm_request_locality(chip, flags);
-		if (rc < 0)
-			goto out_no_locality;
+		if (rc < 0) {
+			need_locality = false;
+			goto out_locality;
+		}
 	}
 
 	rc = tpm_cmd_ready(chip, flags);
 	if (rc)
-		goto out;
+		goto out_locality;
 
 	rc = tpm2_prepare_space(chip, space, ordinal, buf);
 	if (rc)
@@ -547,14 +549,13 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
 		dev_err(&chip->dev, "tpm2_commit_space: error %d\n", rc);
 
 out:
-	rc = tpm_go_idle(chip, flags);
-	if (rc)
-		goto out;
+	/* may fail but do not override previous error value in rc */
+	tpm_go_idle(chip, flags);
 
+out_locality:
 	if (need_locality)
 		tpm_relinquish_locality(chip, flags);
 
-out_no_locality:
 	if (chip->ops->clk_enable != NULL)
 		chip->ops->clk_enable(chip, false);
 
-- 
2.14.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-10-24 17:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-16 13:37 [PATCH] tpm: tpm_try_transmit() refactor error flow Tomas Winkler
2018-10-18  0:14 ` Jarkko Sakkinen
2018-10-18  6:06   ` Winkler, Tomas
2018-10-18  6:06     ` Winkler, Tomas
2018-10-19 23:34     ` Jarkko Sakkinen
2018-10-19 23:34       ` Jarkko Sakkinen
2018-10-20 22:49       ` Winkler, Tomas
2018-10-20 22:49         ` Winkler, Tomas
2018-10-23 13:27         ` Jarkko Sakkinen
2018-10-23 13:27           ` Jarkko Sakkinen
2018-10-23 14:16           ` Winkler, Tomas
2018-10-23 14:16             ` Winkler, Tomas
2018-10-24  8:59             ` Jarkko Sakkinen
2018-10-24  8:59               ` Jarkko Sakkinen
2018-10-24  9:01               ` Winkler, Tomas
2018-10-24  9:01                 ` Winkler, Tomas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.