diff mbox series

[2/2] tpm: tpm_try_transmit() refactor error flow.

Message ID 20190710094112.13345-3-aaron.ma@canonical.com
State New
Headers show
Series Fix resume failure on some TPM chips | expand

Commit Message

Aaron Ma July 10, 2019, 9:41 a.m. UTC
From: Tomas Winkler <tomas.winkler@intel.com>

BugLink: https://bugs.launchpad.net/bugs/1836031

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>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
(cherry picked from commit 01f54664a4db0d612de0ece8e0022f21f9374e9b)
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/char/tpm/tpm-interface.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Kleber Sacilotto de Souza July 11, 2019, 9 a.m. UTC | #1
On 10.07.19 11:41, Aaron Ma wrote:
> From: Tomas Winkler <tomas.winkler@intel.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1836031
> 
> 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>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> (cherry picked from commit 01f54664a4db0d612de0ece8e0022f21f9374e9b)
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>

Only this patch needs review, as Patch 1/1 has already been appiled
as pointed out by Aaron.

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

Thank you,
Kleber

> ---
>  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 f89cb2eb083c..d328e13afda1 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -478,13 +478,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)
> @@ -548,14 +550,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);
>  
>
Connor Kuehl July 16, 2019, 5:56 p.m. UTC | #2
On 7/10/19 2:41 AM, Aaron Ma wrote:
> From: Tomas Winkler <tomas.winkler@intel.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1836031
> 
> 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>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> (cherry picked from commit 01f54664a4db0d612de0ece8e0022f21f9374e9b)
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>

Acked-by: Connor Kuehl <connor.kuehl@canonical.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 f89cb2eb083c..d328e13afda1 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -478,13 +478,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)
> @@ -548,14 +550,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);
>  
>
Khalid Elmously July 17, 2019, 6:37 a.m. UTC | #3
On 2019-07-10 17:41:12 , Aaron Ma wrote:
> From: Tomas Winkler <tomas.winkler@intel.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1836031
> 
> 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>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> (cherry picked from commit 01f54664a4db0d612de0ece8e0022f21f9374e9b)
> Signed-off-by: Aaron Ma <aaron.ma@canonical.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 f89cb2eb083c..d328e13afda1 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -478,13 +478,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)
> @@ -548,14 +550,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.20.1
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
diff mbox series

Patch

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index f89cb2eb083c..d328e13afda1 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -478,13 +478,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)
@@ -548,14 +550,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);