[v9,04/17] tpm: print tpm2_commit_space() error inside tpm2_commit_space()
diff mbox series

Message ID 20181118124753.18613-5-jarkko.sakkinen@linux.intel.com
State New
Headers show
Series
  • Removed nested TPM operations
Related show

Commit Message

Jarkko Sakkinen Nov. 18, 2018, 12:47 p.m. UTC
The error logging for tpm2_commit_space() is in a wrong place. This
commit moves it inside that function.

Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
---
 drivers/char/tpm/tpm-interface.c | 2 --
 drivers/char/tpm/tpm2-space.c    | 9 ++++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

Comments

Winkler, Tomas Nov. 19, 2018, 9:25 p.m. UTC | #1
> 
> The error logging for tpm2_commit_space() is in a wrong place. This commit
> moves it inside that function.
> 
> Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
>  drivers/char/tpm/tpm-interface.c | 2 --
>  drivers/char/tpm/tpm2-space.c    | 9 ++++++---
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> interface.c
> index 64510ed81b46..7ac6ada8428c 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -277,8 +277,6 @@ static ssize_t tpm_try_transmit(struct tpm_chip
> *chip,
>  	}
> 
>  	rc = tpm2_commit_space(chip, space, ordinal, buf, &len);
> -	if (rc)
> -		dev_err(&chip->dev, "tpm2_commit_space: error %d\n", rc);
> 
>  out:
>  	/* may fail but do not override previous error value in rc */ diff --git
> a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index
> 1131a8e7b79b..5ecc73988f7c 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -501,19 +501,19 @@ int tpm2_commit_space(struct tpm_chip *chip,
> struct tpm_space *space,
>  	rc = tpm2_map_response_header(chip, cc, buf, *bufsiz);
>  	if (rc) {
>  		tpm2_flush_space(chip);
> -		return rc;
> +		goto out;
>  	}
> 
>  	rc = tpm2_map_response_body(chip, cc, buf, *bufsiz);
>  	if (rc) {
>  		tpm2_flush_space(chip);
> -		return rc;
> +		goto out;
>  	}
> 
>  	rc = tpm2_save_space(chip);
>  	if (rc) {
>  		tpm2_flush_space(chip);
> -		return rc;
> +		goto out;
>  	}
> 
>  	*bufsiz = be32_to_cpu(header->length); @@ -526,4 +526,7 @@ int
> tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
>  	memcpy(space->session_buf, chip->work_space.session_buf,
> PAGE_SIZE);
> 
>  	return 0;
> +out:
Maybe 'out' is too positive name for an error-only exit point? 
or you can use if (rc) ... dev_err()
> +	dev_err(&chip->dev, "%s: error %d\n", __func__, rc);
> +	return rc;
>  }
> --
> 2.19.1
Jarkko Sakkinen Nov. 20, 2018, 12:49 p.m. UTC | #2
On Mon, Nov 19, 2018 at 09:25:22PM +0000, Winkler, Tomas wrote:
> 
> 
> > 
> > The error logging for tpm2_commit_space() is in a wrong place. This commit
> > moves it inside that function.
> > 
> > Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
> > ---
> >  drivers/char/tpm/tpm-interface.c | 2 --
> >  drivers/char/tpm/tpm2-space.c    | 9 ++++++---
> >  2 files changed, 6 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> > interface.c
> > index 64510ed81b46..7ac6ada8428c 100644
> > --- a/drivers/char/tpm/tpm-interface.c
> > +++ b/drivers/char/tpm/tpm-interface.c
> > @@ -277,8 +277,6 @@ static ssize_t tpm_try_transmit(struct tpm_chip
> > *chip,
> >  	}
> > 
> >  	rc = tpm2_commit_space(chip, space, ordinal, buf, &len);
> > -	if (rc)
> > -		dev_err(&chip->dev, "tpm2_commit_space: error %d\n", rc);
> > 
> >  out:
> >  	/* may fail but do not override previous error value in rc */ diff --git
> > a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index
> > 1131a8e7b79b..5ecc73988f7c 100644
> > --- a/drivers/char/tpm/tpm2-space.c
> > +++ b/drivers/char/tpm/tpm2-space.c
> > @@ -501,19 +501,19 @@ int tpm2_commit_space(struct tpm_chip *chip,
> > struct tpm_space *space,
> >  	rc = tpm2_map_response_header(chip, cc, buf, *bufsiz);
> >  	if (rc) {
> >  		tpm2_flush_space(chip);
> > -		return rc;
> > +		goto out;
> >  	}
> > 
> >  	rc = tpm2_map_response_body(chip, cc, buf, *bufsiz);
> >  	if (rc) {
> >  		tpm2_flush_space(chip);
> > -		return rc;
> > +		goto out;
> >  	}
> > 
> >  	rc = tpm2_save_space(chip);
> >  	if (rc) {
> >  		tpm2_flush_space(chip);
> > -		return rc;
> > +		goto out;
> >  	}
> > 
> >  	*bufsiz = be32_to_cpu(header->length); @@ -526,4 +526,7 @@ int
> > tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
> >  	memcpy(space->session_buf, chip->work_space.session_buf,
> > PAGE_SIZE);
> > 
> >  	return 0;
> > +out:
> Maybe 'out' is too positive name for an error-only exit point? 
> or you can use if (rc) ... dev_err()

out_err?

/Jarkko
Winkler, Tomas Nov. 20, 2018, 1:12 p.m. UTC | #3
> 
> On Mon, Nov 19, 2018 at 09:25:22PM +0000, Winkler, Tomas wrote:
> >
> >
> > >
> > > The error logging for tpm2_commit_space() is in a wrong place. This
> > > commit moves it inside that function.
> > >
> > > Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
> > > ---
> > >  drivers/char/tpm/tpm-interface.c | 2 --
> > >  drivers/char/tpm/tpm2-space.c    | 9 ++++++---
> > >  2 files changed, 6 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/char/tpm/tpm-interface.c
> > > b/drivers/char/tpm/tpm- interface.c index 64510ed81b46..7ac6ada8428c
> > > 100644
> > > --- a/drivers/char/tpm/tpm-interface.c
> > > +++ b/drivers/char/tpm/tpm-interface.c
> > > @@ -277,8 +277,6 @@ static ssize_t tpm_try_transmit(struct tpm_chip
> > > *chip,
> > >  	}
> > >
> > >  	rc = tpm2_commit_space(chip, space, ordinal, buf, &len);
> > > -	if (rc)
> > > -		dev_err(&chip->dev, "tpm2_commit_space: error %d\n", rc);
> > >
> > >  out:
> > >  	/* may fail but do not override previous error value in rc */ diff
> > > --git a/drivers/char/tpm/tpm2-space.c
> > > b/drivers/char/tpm/tpm2-space.c index 1131a8e7b79b..5ecc73988f7c
> > > 100644
> > > --- a/drivers/char/tpm/tpm2-space.c
> > > +++ b/drivers/char/tpm/tpm2-space.c
> > > @@ -501,19 +501,19 @@ int tpm2_commit_space(struct tpm_chip *chip,
> > > struct tpm_space *space,
> > >  	rc = tpm2_map_response_header(chip, cc, buf, *bufsiz);
> > >  	if (rc) {
> > >  		tpm2_flush_space(chip);
> > > -		return rc;
> > > +		goto out;
> > >  	}
> > >
> > >  	rc = tpm2_map_response_body(chip, cc, buf, *bufsiz);
> > >  	if (rc) {
> > >  		tpm2_flush_space(chip);
> > > -		return rc;
> > > +		goto out;
> > >  	}
> > >
> > >  	rc = tpm2_save_space(chip);
> > >  	if (rc) {
> > >  		tpm2_flush_space(chip);
> > > -		return rc;
> > > +		goto out;
> > >  	}
> > >
> > >  	*bufsiz = be32_to_cpu(header->length); @@ -526,4 +526,7 @@ int
> > > tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
> > >  	memcpy(space->session_buf, chip->work_space.session_buf,
> > > PAGE_SIZE);
> > >
> > >  	return 0;
> > > +out:
> > Maybe 'out' is too positive name for an error-only exit point?
> > or you can use if (rc) ... dev_err()
> 
> out_err?
out_err is good, it is used in more places, so it has some of consistency.
Thanks
Tomas



> 
> /Jarkko

Patch
diff mbox series

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 64510ed81b46..7ac6ada8428c 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -277,8 +277,6 @@  static ssize_t tpm_try_transmit(struct tpm_chip *chip,
 	}
 
 	rc = tpm2_commit_space(chip, space, ordinal, buf, &len);
-	if (rc)
-		dev_err(&chip->dev, "tpm2_commit_space: error %d\n", rc);
 
 out:
 	/* may fail but do not override previous error value in rc */
diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
index 1131a8e7b79b..5ecc73988f7c 100644
--- a/drivers/char/tpm/tpm2-space.c
+++ b/drivers/char/tpm/tpm2-space.c
@@ -501,19 +501,19 @@  int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
 	rc = tpm2_map_response_header(chip, cc, buf, *bufsiz);
 	if (rc) {
 		tpm2_flush_space(chip);
-		return rc;
+		goto out;
 	}
 
 	rc = tpm2_map_response_body(chip, cc, buf, *bufsiz);
 	if (rc) {
 		tpm2_flush_space(chip);
-		return rc;
+		goto out;
 	}
 
 	rc = tpm2_save_space(chip);
 	if (rc) {
 		tpm2_flush_space(chip);
-		return rc;
+		goto out;
 	}
 
 	*bufsiz = be32_to_cpu(header->length);
@@ -526,4 +526,7 @@  int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
 	memcpy(space->session_buf, chip->work_space.session_buf, PAGE_SIZE);
 
 	return 0;
+out:
+	dev_err(&chip->dev, "%s: error %d\n", __func__, rc);
+	return rc;
 }