Xen vTPM frontend: Fine-tuning for vtpm_send()
Subsystems (3)
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
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
@@ -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
PATCH 2/2 xen-tpmfront: Combine two condition checks into one statement in vtpm_send()
In reply to SF Markus ElfringFrom: 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
@@ -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
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 +0200A 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
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:23:45 +0200Two 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 statementdrivers/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
Jarkko Sakkinen
NAKRe: [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send()
In reply to SF Markus ElfringQuoted 50 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 12:56:42 +0200Add 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 <[email protected]>--- drivers/char/tpm/xen-tpmfront.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/char/tpm/xen-tpmfront.c +7
-6@@ -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
Re: [PATCH 2/2] xen-tpmfront: Combine two condition checks into one statement in vtpm_send()
In reply to SF Markus ElfringQuoted 30 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:15:16 +0200A return was performed with the same error code after two condition checks. Thus use a single statement instead.
Signed-off-by Markus Elfring <[email protected]>--- drivers/char/tpm/xen-tpmfront.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/char/tpm/xen-tpmfront.c +1
-4@@ -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
Re: [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send()
In reply to Jarkko SakkinenQuoted 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
-0static int vtpm_recv (struct tpm_chip *chip,u8 *buf,size_t count)Signature · 1 line
2.14.2NAK
Do you need any more facts to show the influence of the proposed small code reduction?
Regards,
Markus
Re: [PATCH 2/2] xen-tpmfront: Combine two condition checks into one statement in vtpm_send()
In reply to Jarkko SakkinenQuoted 34 lines · Jarkko Sakkinen
Quoted 30 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 13:15:16 +0200A return was performed with the same error code after two condition checks. Thus use a single statement instead.
Signed-off-by Markus Elfring <[email protected]>--- drivers/char/tpm/xen-tpmfront.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/char/tpm/xen-tpmfront.c +1
-4@@ -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.2This is fine.
Quoted 3 lines
Reviewed-by Jarkko Sakkinen <[email protected]>/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
Re: [PATCH 1/2] xen-tpmfront: Use common error handling code in vtpm_send()
In reply to SF Markus ElfringQuoted 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
-0static int vtpm_recv (struct tpm_chip *chip,u8 *buf,size_t count)Signature · 1 line
2.14.2NAK
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