diff mbox series

[v6,2/8] tpm: Remove tpm_send()

Message ID 20231124020237.27116-3-jarkko@kernel.org (mailing list archive)
State New
Headers show
Series Extend struct tpm_buf to support sized buffers (TPM2B) | expand

Commit Message

Jarkko Sakkinen Nov. 24, 2023, 2:02 a.m. UTC
Open code the last remaining call site for tpm_send().

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
v1 [2023-11-21]: A new patch.
---
 drivers/char/tpm/tpm-interface.c          | 25 -----------------------
 include/linux/tpm.h                       |  5 -----
 security/keys/trusted-keys/trusted_tpm1.c | 14 +++++++++++--
 3 files changed, 12 insertions(+), 32 deletions(-)

Comments

Stefan Berger Nov. 27, 2023, 8:37 p.m. UTC | #1
On 11/23/23 21:02, Jarkko Sakkinen wrote:
> Open code the last remaining call site for tpm_send().
> 
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>

> ---
> v1 [2023-11-21]: A new patch.
> ---
>   drivers/char/tpm/tpm-interface.c          | 25 -----------------------
>   include/linux/tpm.h                       |  5 -----
>   security/keys/trusted-keys/trusted_tpm1.c | 14 +++++++++++--
>   3 files changed, 12 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 66b16d26eecc..163ae247bff2 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -342,31 +342,6 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
>   }
>   EXPORT_SYMBOL_GPL(tpm_pcr_extend);
>   
> -/**
> - * tpm_send - send a TPM command
> - * @chip:	a &struct tpm_chip instance, %NULL for the default chip
> - * @cmd:	a TPM command buffer
> - * @buflen:	the length of the TPM command buffer
> - *
> - * Return: same as with tpm_transmit_cmd()
> - */
> -int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
> -{
> -	struct tpm_buf buf;
> -	int rc;
> -
> -	chip = tpm_find_get_ops(chip);
> -	if (!chip)
> -		return -ENODEV;
> -
> -	buf.data = cmd;
> -	rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command");
> -
> -	tpm_put_ops(chip);
> -	return rc;
> -}
> -EXPORT_SYMBOL_GPL(tpm_send);
> -
>   int tpm_auto_startup(struct tpm_chip *chip)
>   {
>   	int rc;
> diff --git a/include/linux/tpm.h b/include/linux/tpm.h
> index 6588ca87cf93..d9d645e9c52c 100644
> --- a/include/linux/tpm.h
> +++ b/include/linux/tpm.h
> @@ -422,7 +422,6 @@ extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
>   			struct tpm_digest *digest);
>   extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
>   			  struct tpm_digest *digests);
> -extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
>   extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
>   extern struct tpm_chip *tpm_default_chip(void);
>   void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
> @@ -443,10 +442,6 @@ static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
>   	return -ENODEV;
>   }
>   
> -static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
> -{
> -	return -ENODEV;
> -}
>   static inline int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max)
>   {
>   	return -ENODEV;
> diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c
> index aa108bea6739..37bce84eef99 100644
> --- a/security/keys/trusted-keys/trusted_tpm1.c
> +++ b/security/keys/trusted-keys/trusted_tpm1.c
> @@ -356,17 +356,27 @@ static int TSS_checkhmac2(unsigned char *buffer,
>    */
>   int trusted_tpm_send(unsigned char *cmd, size_t buflen)
>   {
> +	struct tpm_buf buf;
>   	int rc;
>   
>   	if (!chip)
>   		return -ENODEV;
>   
> +	rc = tpm_try_get_ops(chip);
> +	if (rc)
> +		return rc;
> +
> +	buf.flags = 0;
> +	buf.data = cmd;
>   	dump_tpm_buf(cmd);
> -	rc = tpm_send(chip, cmd, buflen);
> +	rc = tpm_transmit_cmd(chip, &buf, 4, "sending data");
>   	dump_tpm_buf(cmd);
> +
>   	if (rc > 0)
> -		/* Can't return positive return codes values to keyctl */
> +		/* TPM error */
>   		rc = -EPERM;
> +
> +	tpm_put_ops(chip);
>   	return rc;
>   }
>   EXPORT_SYMBOL_GPL(trusted_tpm_send);
diff mbox series

Patch

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 66b16d26eecc..163ae247bff2 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -342,31 +342,6 @@  int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
 }
 EXPORT_SYMBOL_GPL(tpm_pcr_extend);
 
-/**
- * tpm_send - send a TPM command
- * @chip:	a &struct tpm_chip instance, %NULL for the default chip
- * @cmd:	a TPM command buffer
- * @buflen:	the length of the TPM command buffer
- *
- * Return: same as with tpm_transmit_cmd()
- */
-int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
-{
-	struct tpm_buf buf;
-	int rc;
-
-	chip = tpm_find_get_ops(chip);
-	if (!chip)
-		return -ENODEV;
-
-	buf.data = cmd;
-	rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command");
-
-	tpm_put_ops(chip);
-	return rc;
-}
-EXPORT_SYMBOL_GPL(tpm_send);
-
 int tpm_auto_startup(struct tpm_chip *chip)
 {
 	int rc;
diff --git a/include/linux/tpm.h b/include/linux/tpm.h
index 6588ca87cf93..d9d645e9c52c 100644
--- a/include/linux/tpm.h
+++ b/include/linux/tpm.h
@@ -422,7 +422,6 @@  extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
 			struct tpm_digest *digest);
 extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
 			  struct tpm_digest *digests);
-extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
 extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
 extern struct tpm_chip *tpm_default_chip(void);
 void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
@@ -443,10 +442,6 @@  static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
 	return -ENODEV;
 }
 
-static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
-{
-	return -ENODEV;
-}
 static inline int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max)
 {
 	return -ENODEV;
diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c
index aa108bea6739..37bce84eef99 100644
--- a/security/keys/trusted-keys/trusted_tpm1.c
+++ b/security/keys/trusted-keys/trusted_tpm1.c
@@ -356,17 +356,27 @@  static int TSS_checkhmac2(unsigned char *buffer,
  */
 int trusted_tpm_send(unsigned char *cmd, size_t buflen)
 {
+	struct tpm_buf buf;
 	int rc;
 
 	if (!chip)
 		return -ENODEV;
 
+	rc = tpm_try_get_ops(chip);
+	if (rc)
+		return rc;
+
+	buf.flags = 0;
+	buf.data = cmd;
 	dump_tpm_buf(cmd);
-	rc = tpm_send(chip, cmd, buflen);
+	rc = tpm_transmit_cmd(chip, &buf, 4, "sending data");
 	dump_tpm_buf(cmd);
+
 	if (rc > 0)
-		/* Can't return positive return codes values to keyctl */
+		/* TPM error */
 		rc = -EPERM;
+
+	tpm_put_ops(chip);
 	return rc;
 }
 EXPORT_SYMBOL_GPL(trusted_tpm_send);