linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm: fix tpm_transmit() parameters
@ 2016-04-05 14:23 Jarkko Sakkinen
  2016-04-05 15:25 ` Peter Huewe
  0 siblings, 1 reply; 3+ messages in thread
From: Jarkko Sakkinen @ 2016-04-05 14:23 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Christophe Ricard, Jarkko Sakkinen, Marcel Selhorst,
	Jason Gunthorpe, moderated list:TPM DEVICE DRIVER, open list

Changed the type of 'buf' from 'const char *' to 'u8*' because the
contents of the 'buf' get modified by the function and to better match
the API in struct tpm_class_ops. Renamed 'bufsize' to 'len' in order to
better match the API in struct tpm_class_ops.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm-interface.c | 15 +++++++--------
 drivers/char/tpm/tpm.h           |  3 +--
 drivers/char/tpm/tpm2-cmd.c      |  2 +-
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 316c784..c82f31f 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -330,29 +330,28 @@ EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
 /*
  * Internal kernel interface to transmit TPM commands
  */
-ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
-		     size_t bufsiz)
+ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t len)
 {
 	ssize_t rc;
 	u32 count, ordinal;
 	unsigned long stop;
 
-	if (bufsiz > TPM_BUFSIZE)
-		bufsiz = TPM_BUFSIZE;
+	if (len > TPM_BUFSIZE)
+		len = TPM_BUFSIZE;
 
 	count = be32_to_cpu(*((__be32 *) (buf + 2)));
 	ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
 	if (count == 0)
 		return -ENODATA;
-	if (count > bufsiz) {
+	if (count > len) {
 		dev_err(&chip->dev,
-			"invalid count value %x %zx\n", count, bufsiz);
+			"invalid count value %x %zx\n", count, len);
 		return -E2BIG;
 	}
 
 	mutex_lock(&chip->tpm_mutex);
 
-	rc = chip->ops->send(chip, (u8 *) buf, count);
+	rc = chip->ops->send(chip, buf, count);
 	if (rc < 0) {
 		dev_err(&chip->dev,
 			"tpm_transmit: tpm_send: error %zd\n", rc);
@@ -388,7 +387,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
 	goto out;
 
 out_recv:
-	rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
+	rc = chip->ops->recv(chip, buf, len);
 	if (rc < 0)
 		dev_err(&chip->dev,
 			"tpm_transmit: tpm_recv: error %zd\n", rc);
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 154984b..4126b04 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -472,8 +472,7 @@ extern const struct file_operations tpm_fops;
 extern struct idr dev_nums_idr;
 
 ssize_t	tpm_getcap(struct device *, __be32, cap_t *, const char *);
-ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
-		     size_t bufsiz);
+ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t len);
 ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd, int len,
 			 const char *desc);
 extern int tpm_get_timeouts(struct tpm_chip *);
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 552b3ee..8f47206 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -921,7 +921,7 @@ int tpm2_probe(struct tpm_chip *chip)
 	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(0x100);
 	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
 
-	rc = tpm_transmit(chip, (const char *) &cmd, sizeof(cmd));
+	rc = tpm_transmit(chip, (u8 *) &cmd, sizeof(cmd));
 	if (rc <  0)
 		return rc;
 	else if (rc < TPM_HEADER_SIZE)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tpm: fix tpm_transmit() parameters
  2016-04-05 14:23 [PATCH] tpm: fix tpm_transmit() parameters Jarkko Sakkinen
@ 2016-04-05 15:25 ` Peter Huewe
  2016-04-07 10:12   ` Jarkko Sakkinen
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Huewe @ 2016-04-05 15:25 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Christophe Ricard, Marcel Selhorst, Jason Gunthorpe, tpmdd-devel,
	linux-kernel

Reviewed-by: Peter Huewe <peterhuewe@gmx.de>
-- 
Sent from my mobile

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tpm: fix tpm_transmit() parameters
  2016-04-05 15:25 ` Peter Huewe
@ 2016-04-07 10:12   ` Jarkko Sakkinen
  0 siblings, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2016-04-07 10:12 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Christophe Ricard, Marcel Selhorst, Jason Gunthorpe, tpmdd-devel,
	linux-kernel

On Tue, Apr 05, 2016 at 08:25:58AM -0700, Peter Huewe wrote:
> Reviewed-by: Peter Huewe <peterhuewe@gmx.de>

Thanks Peter. I'll include this to a patch set that I'm sending a bit
later that unifies the API to use one function everywhere. Now we have
both tpm_transmit() and tpm_transmit_cmd(), which does not make sense.

> -- 
> Sent from my mobile

/Jarkko

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-07 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-05 14:23 [PATCH] tpm: fix tpm_transmit() parameters Jarkko Sakkinen
2016-04-05 15:25 ` Peter Huewe
2016-04-07 10:12   ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).