tpm: move TPM space code out of tpm_transmit()

Prepare and commit TPM space before and after calling tpm_transmit()
instead of doing that inside tpm_transmit(). After this change we can
remove TPM_TRANSMIT_NESTED flag from tpm2_prepare_space() and
tpm2_commit_space() and replace it with TPM_TRANSMIT_UNLOCKED.

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>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
This commit is contained in:
Jarkko Sakkinen
2018-11-03 05:22:36 +02:00
parent c3465a370f
commit 29b47ce987
3 changed files with 34 additions and 33 deletions

View File

@@ -145,27 +145,12 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
return -E2BIG;
}
rc = tpm2_prepare_space(chip, space, buf, bufsiz);
/*
* If the command is not implemented by the TPM, synthesize a
* response with a TPM2_RC_COMMAND_CODE return for user-space.
*/
if (rc == -EOPNOTSUPP) {
header->length = cpu_to_be32(sizeof(*header));
header->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS);
header->return_code = cpu_to_be32(TPM2_RC_COMMAND_CODE |
TSS2_RESMGR_TPM_RC_LAYER);
return sizeof(*header);
}
if (rc)
return rc;
rc = chip->ops->send(chip, buf, count);
if (rc < 0) {
if (rc != -EPIPE)
dev_err(&chip->dev,
"%s: send(): error %d\n", __func__, rc);
goto out_rc;
return rc;
}
/* A sanity check. send() should just return zero on success e.g.
@@ -189,8 +174,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
if (chip->ops->req_canceled(chip, status)) {
dev_err(&chip->dev, "Operation Canceled\n");
rc = -ECANCELED;
goto out_rc;
return -ECANCELED;
}
tpm_msleep(TPM_TIMEOUT_POLL);
@@ -199,8 +183,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
chip->ops->cancel(chip);
dev_err(&chip->dev, "Operation Timed out\n");
rc = -ETIME;
goto out_rc;
return -ETIME;
out_recv:
len = chip->ops->recv(chip, buf, bufsiz);
@@ -210,10 +193,6 @@ out_recv:
} else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length))
rc = -EFAULT;
out_rc:
if (!rc)
rc = tpm2_commit_space(chip, space, buf, &len);
return rc ? rc : len;
}