linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-integrity@vger.kernel.org,
	"Jarkko Sakkinen" <jarkko.sakkinen@linux.intel.com>,
	"Jason Gunthorpe" <jgunthorpe@obsidianresearch.com>,
	"Peter Hüwe" <PeterHuewe@gmx.de>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send()
Date: Sun, 22 Oct 2017 13:29:33 +0200	[thread overview]
Message-ID: <9cfcbfd0-75c3-4de5-f735-0ace23d2abcb@users.sourceforge.net> (raw)
In-Reply-To: <cf592c7d-8fbc-833b-fa1a-ff9e91c3734c@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Oct 2017 12:56:42 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/char/tpm/xen-tpmfront.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index 656e8af95d52..873a5631937a 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -90,10 +90,8 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
 
 	/* Wait for completion of any existing command or cancellation */
 	if (wait_for_tpm_stat(chip, VTPM_STATUS_IDLE, chip->timeout_c,
-			&priv->read_queue, true) < 0) {
-		vtpm_cancel(chip);
-		return -ETIME;
-	}
+			      &priv->read_queue, true) < 0)
+		goto cancel_vtpm;
 
 	memcpy(offset + (u8 *)shr, buf, count);
 	shr->length = count;
@@ -108,11 +106,14 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
 	if (wait_for_tpm_stat(chip, VTPM_STATUS_IDLE, duration,
 			&priv->read_queue, true) < 0) {
 		/* got a signal or timeout, try to cancel */
-		vtpm_cancel(chip);
-		return -ETIME;
+		goto cancel_vtpm;
 	}
 
 	return count;
+
+cancel_vtpm:
+	vtpm_cancel(chip);
+	return -ETIME;
 }
 
 static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
-- 
2.14.2

  reply	other threads:[~2017-10-22 11:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-22 11:28 [PATCH 0/2] Xen vTPM frontend: Fine-tuning for vtpm_send() SF Markus Elfring
2017-10-22 11:29 ` SF Markus Elfring [this message]
2017-10-23 13:42   ` [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send() Jarkko Sakkinen
2017-10-23 13:57     ` SF Markus Elfring
2017-10-24 13:56       ` Jarkko Sakkinen
2017-10-22 11:30 ` [PATCH 2/2] xen-tpmfront: Combine two condition checks into one statement " SF Markus Elfring
2017-10-23  7:31   ` Dan Carpenter
2017-10-23 13:44   ` Jarkko Sakkinen
2017-10-24 13:52     ` Jarkko Sakkinen
2017-10-23 13:42 ` [PATCH 0/2] Xen vTPM frontend: Fine-tuning for vtpm_send() Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9cfcbfd0-75c3-4de5-f735-0ace23d2abcb@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=PeterHuewe@gmx.de \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).