Skip to contentSkip to conversation

Xen vTPM frontend: Fine-tuning for vtpm_send()

PATCH NAK SF Markus Elfring 3 participants 10 messages Oct 22, 2017 – Oct 24, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Xen vTPM frontend: Fine-tuning for vtpm_send()

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:23:45 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use common error handling code
Combine two condition checks into one statement

 drivers/char/tpm/xen-tpmfront.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
Signature · 1 line
2.14.2
#1 lore raw

PATCH 1/2 xen-tpmfront: Use common error handling code in vtpm_send()

From: Markus Elfring <[email protected]>
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.

---
 drivers/char/tpm/xen-tpmfront.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/char/tpm/xen-tpmfront.c +7 -6
index 656e8af95d52..873a5631937a 100644
@@ -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)
Signature · 1 line
2.14.2
#5 lore raw

PATCH 2/2 xen-tpmfront: Combine two condition checks into one statement in vtpm_send()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:15:16 +0200

A return was performed with the same error code after two condition checks. Thus use a single statement instead.

---
 drivers/char/tpm/xen-tpmfront.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/char/tpm/xen-tpmfront.c +1 -4
index 873a5631937a..0d02743e7a87 100644
@@ -82,10 +82,7 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
 	u32 ordinal;
 	unsigned long duration;
 
-	if (offset > PAGE_SIZE)
-		return -EINVAL;
-
-	if (offset + count > PAGE_SIZE)
+	if (offset > PAGE_SIZE || offset + count > PAGE_SIZE)
 		return -EINVAL;
 
 	/* Wait for completion of any existing command or cancellation */
Signature · 1 line
2.14.2
#6 lore raw

Re: [PATCH 2/2] xen-tpmfront: Combine two condition checks into one statement in vtpm_send()

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:15:16 +0200

A return was performed with the same error code after two condition checks. Thus use a single statement instead.

It's fine as-is, thanks.

regards,
dan carpenter

#9 lore raw
In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:23:45 +0200

Two update suggestions were taken into account
from static source code analysis.

Quoted 10 lines

Markus Elfring (2):
Use common error handling code
Combine two condition checks into one statement

 drivers/char/tpm/xen-tpmfront.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
Signature · 1 line
2.14.2

Useless cover letter. Two separate unrelated patches.

/Jarkko

#2 lore raw

Re: [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send()

In reply to SF Markus Elfring
Quoted 50 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/char/tpm/xen-tpmfront.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/char/tpm/xen-tpmfront.c +7 -6
index 656e8af95d52..873a5631937a 100644
@@ -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)
Signature · 1 line
2.14.2

NAK

/Jarkko

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] xen-tpmfront: Combine two condition checks into one statement in vtpm_send()

In reply to SF Markus Elfring
Quoted 30 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:15:16 +0200

A return was performed with the same error code after two condition checks. Thus use a single statement instead.

---
 drivers/char/tpm/xen-tpmfront.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/char/tpm/xen-tpmfront.c +1 -4
index 873a5631937a..0d02743e7a87 100644
@@ -82,10 +82,7 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
 	u32 ordinal;
 	unsigned long duration;
 
-	if (offset > PAGE_SIZE)
-		return -EINVAL;
-
-	if (offset + count > PAGE_SIZE)
+	if (offset > PAGE_SIZE || offset + count > PAGE_SIZE)
 		return -EINVAL;
 
 	/* Wait for completion of any existing command or cancellation */
Signature · 1 line
2.14.2

This is fine.

/Jarkko

#3 lore raw

Re: [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send()

In reply to Jarkko Sakkinen
Quoted 16 lines
Quoted 16 lines
drivers/char/tpm/xen-tpmfront.c +5 -2
@@ -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;
 }
 
Quoted 6 lines
Quoted 4 lines
drivers/char/tpm/xen-tpmfront.c +0 -0
 static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
Signature · 1 line
2.14.2

NAK

Do you need any more facts to show the influence of the proposed small code reduction?

Regards,
Markus

#8 lore raw

Re: [PATCH 2/2] xen-tpmfront: Combine two condition checks into one statement in vtpm_send()

In reply to Jarkko Sakkinen
Quoted 34 lines · Jarkko Sakkinen
Quoted 30 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:15:16 +0200

A return was performed with the same error code after two condition checks. Thus use a single statement instead.

---
 drivers/char/tpm/xen-tpmfront.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/char/tpm/xen-tpmfront.c +1 -4
index 873a5631937a..0d02743e7a87 100644
@@ -82,10 +82,7 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
 	u32 ordinal;
 	unsigned long duration;
 
-	if (offset > PAGE_SIZE)
-		return -EINVAL;
-
-	if (offset + count > PAGE_SIZE)
+	if (offset > PAGE_SIZE || offset + count > PAGE_SIZE)
 		return -EINVAL;
 
 	/* Wait for completion of any existing command or cancellation */
Signature · 1 line
2.14.2

This is fine.

Quoted 3 lines

/Jarkko

Anyway I NAK it because it is really a change of insignificant value. Just adds cruft to the kernel release.

I would be fine if someone did this as part of something significant.

/Jarkko

#4 lore raw

Re: [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send()

In reply to SF Markus Elfring
Quoted 23 lines · SF Markus Elfring
Quoted 16 lines
Quoted 16 lines
drivers/char/tpm/xen-tpmfront.c +5 -2
@@ -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;
 }
 
Quoted 6 lines
Quoted 4 lines
drivers/char/tpm/xen-tpmfront.c +0 -0
 static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
Signature · 1 line
2.14.2

NAK

Quoted 4 lines

Do you need any more facts to show the influence of the proposed small code reduction?

Regards,
Markus

Already explained when I reviewed another patch dealing with -ETIME.

/Jarkko