diff mbox

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

Message ID 9cfcbfd0-75c3-4de5-f735-0ace23d2abcb@users.sourceforge.net (mailing list archive)
State New, archived
Headers show

Commit Message

SF Markus Elfring Oct. 22, 2017, 11:29 a.m. UTC
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(-)

Comments

Jarkko Sakkinen Oct. 23, 2017, 1:42 p.m. UTC | #1
On Sun, Oct 22, 2017 at 01:29:33PM +0200, SF Markus Elfring wrote:
> 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
> 

NAK

/Jarkko
SF Markus Elfring Oct. 23, 2017, 1:57 p.m. UTC | #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;
>>  }
>>  
>>  static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
>> -- 
>> 2.14.2
>>
> 
> NAK

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

Regards,
Markus
Jarkko Sakkinen Oct. 24, 2017, 1:56 p.m. UTC | #3
On Mon, Oct 23, 2017 at 03:57:30PM +0200, SF Markus Elfring wrote:
> >> @@ -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
> >>
> > 
> > NAK
> 
> 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
diff mbox

Patch

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)