tpm: Unify send() callbacks
Subsystems (6)
v3 cover tpm: Unify send() callbacks
A portion of send() callbacks have returned length, in many cases just returning back what was given as an argument, and tpm_crb has returned 0 on success. This patch set fixes and unifies the behaviour.
v3:tpm_tis_core fix was left out of the staging area :-(
v2:
The drivers tpm_nsc and tpm_infineon were forgotten. For this version I checked both with find and command and from Kconfig that everything that is supposed to be a driver directly interfacing with the TPM core, is included (e.g. discluding tpm_tis_spi).
Jarkko Sakkinen (2):
tpm: Unify the send callback behaviour tpm/tpm_i2c_atmel: Return -E2BIG when the transfer is incomplete
drivers/char/tpm/st33zp24/st33zp24.c | 2 +- drivers/char/tpm/tpm_atmel.c | 2 +- drivers/char/tpm/tpm_i2c_atmel.c | 10 +++++++++- drivers/char/tpm/tpm_i2c_infineon.c | 2 +- drivers/char/tpm/tpm_i2c_nuvoton.c | 2 +- drivers/char/tpm/tpm_ibmvtpm.c | 2 +- drivers/char/tpm/tpm_infineon.c | 2 +- drivers/char/tpm/tpm_nsc.c | 2 +- drivers/char/tpm/tpm_tis_core.c | 6 +++++- drivers/char/tpm/tpm_vtpm_proxy.c | 3 +-- drivers/char/tpm/xen-tpmfront.c | 2 +- 11 files changed, 23 insertions(+), 12 deletions(-)
Signature · 1 line
2.19.1
PATCH v3 1/2 tpm: Unify the send callback behaviour
The send() callback should never return length as it does not in every driver except tpm_crb in the success case. The reason is that the main transmit functionality only cares about whether the transmit was successful or not and ignores the count completely.
--- drivers/char/tpm/st33zp24/st33zp24.c | 2 +- drivers/char/tpm/tpm_atmel.c | 2 +- drivers/char/tpm/tpm_i2c_atmel.c | 6 +++++- drivers/char/tpm/tpm_i2c_infineon.c | 2 +- drivers/char/tpm/tpm_i2c_nuvoton.c | 2 +- drivers/char/tpm/tpm_ibmvtpm.c | 2 +- drivers/char/tpm/tpm_infineon.c | 2 +- drivers/char/tpm/tpm_nsc.c | 2 +- drivers/char/tpm/tpm_tis_core.c | 6 +++++- drivers/char/tpm/tpm_vtpm_proxy.c | 3 +-- drivers/char/tpm/xen-tpmfront.c | 2 +- 11 files changed, 19 insertions(+), 12 deletions(-)
drivers/char/tpm/st33zp24/st33zp24.c +1 -1
@@ -436,7 +436,7 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf, goto out_err; } -return len; +return 0 ; out_err:st33zp24_cancel (chip);release_locality (chip);
drivers/char/tpm/tpm_atmel.c +1 -1
@@ -105,7 +105,7 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)iowrite8 (buf[i], priv->iobase); } -return count; +return 0 ; }static void tpm_atml_cancel (struct tpm_chip *chip)
drivers/char/tpm/tpm_i2c_atmel.c +5 -1
@@ -65,7 +65,11 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)dev_dbg (&chip->dev,"%s(buf=%*ph len=%0zx) -> sts=%d\n" , __func__, (int )min_t (size_t,64 , len), buf, len, status); -return status; + +if (status <0 ) +return status; + +return 0 ; }static int i2c_atmel_recv (struct tpm_chip *chip,u8 *buf,size_t count)
drivers/char/tpm/tpm_i2c_infineon.c +1 -1
@@ -588,7 +588,7 @@ static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)/* go and do it */ iic_tpm_write (TPM_STS (tpm_dev.locality), &sts,1 ); -return len; +return 0 ; out_err:tpm_tis_i2c_ready (chip);/* The TPM needs some time to clean up here,
drivers/char/tpm/tpm_i2c_nuvoton.c +1 -1
@@ -465,7 +465,7 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) }dev_dbg (dev,"%s() -> %zd\n" , __func__, len); -return len; +return 0 ; }static bool i2c_nuvoton_req_canceled (struct tpm_chip *chip,u8 status)
drivers/char/tpm/tpm_ibmvtpm.c +1 -1
@@ -192,7 +192,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) rc =0 ; ibmvtpm->tpm_processing_cmd = false; }else - rc = count; + rc =0 ;spin_unlock (&ibmvtpm->rtce_lock);return rc;
drivers/char/tpm/tpm_infineon.c +1 -1
@@ -354,7 +354,7 @@ static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count)for (i =0 ; i < count; i++) {wait_and_send (chip, buf[i]); } -return count; +return 0 ; }static void tpm_inf_cancel (struct tpm_chip *chip)
drivers/char/tpm/tpm_nsc.c +1 -1
@@ -226,7 +226,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) }outb (NSC_COMMAND_EOC , priv->base +NSC_COMMAND ); -return count; +return 0 ; }static void tpm_nsc_cancel (struct tpm_chip *chip)
drivers/char/tpm/tpm_tis_core.c +5 -1
@@ -507,7 +507,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)if (!priv->irq_tested)disable_interrupts (chip); priv->irq_tested = true; -return rc; + +if (rc <0 ) +return rc; + +return 0 ; }struct tis_vendor_timeout_override {
drivers/char/tpm/tpm_vtpm_proxy.c +1 -2
@@ -335,7 +335,6 @@ static int vtpm_proxy_is_driver_command(struct tpm_chip *chip,static int vtpm_proxy_tpm_op_send (struct tpm_chip *chip,u8 *buf,size_t count) {struct proxy_dev *proxy_dev =dev_get_drvdata (&chip->dev); -int rc =0 ;if (count >sizeof (proxy_dev->buffer)) { dev_err(&chip->dev,
@@ -366,7 +365,7 @@ static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count)wake_up_interruptible (&proxy_dev->wq); -return rc; +return 0 ; }static void vtpm_proxy_tpm_op_cancel (struct tpm_chip *chip)
drivers/char/tpm/xen-tpmfront.c +1 -1
@@ -173,7 +173,7 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)return -ETIME ; } -return count; +return 0 ; }static int vtpm_recv (struct tpm_chip *chip,u8 *buf,size_t count)
Signature · 1 line
2.19.1
PATCH v3 2/2 tpm/tpm_i2c_atmel: Return -E2BIG when the transfer is incomplete
In reply to Jarkko SakkinenReturn -E2BIG when the transfer is incomplete. The upper layer does not retry, so not doing that is incorrect behaviour.
--- drivers/char/tpm/tpm_i2c_atmel.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/char/tpm/tpm_i2c_atmel.c +4 -0
@@ -69,6 +69,10 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)if (status <0 )return status; +/* The upper layer does not support incomplete sends. */ +if (status != len) +return -E2BIG ; +return 0 ; }
Signature · 1 line
2.19.1
Re: [PATCH v3 1/2] tpm: Unify the send callback behaviour
In reply to Jarkko SakkinenQuoted 6 lines · Jarkko Sakkinen
static void
tpm_nsc_cancel(struct tpm_chip *chip)drivers/char/tpm/tpm_tis_core.c +0
-0
drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 515
Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +5
-1@@ -507,7 +507,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)if (!priv->irq_tested)disable_interrupts (chip); priv->irq_tested = true; -return rc; + +if (rc <0 ) +return rc; + +return 0 ; }
That's not all... There's this above it as well with tpm_tis_send_main returning with 'return len;'.
if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) return tpm_tis_send_main(chip, buf, len);
Re: [PATCH v3 2/2] tpm/tpm_i2c_atmel: Return -E2BIG when the transfer is incomplete
In reply to Jarkko SakkinenQuoted 15 lines · Jarkko Sakkinen
Return
-E2BIGwhen the transfer is incomplete. The upper layer does not retry, so not doing that is incorrect behaviour.Fixes a2871c62e186 ("tpm: Add support for Atmel I2C TPMs")Signed-off-by Jarkko Sakkinen <[email protected]>--- drivers/char/tpm/tpm_i2c_atmel.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/char/tpm/tpm_i2c_atmel.c +0
-0
drivers/char/tpm/tpm_i2c_atmel.c static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 78
Quoted 10 lines
drivers/char/tpm/tpm_i2c_atmel.c +4
-0@@ -69,6 +69,10 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)if (status <0 )return status; +/* The upper layer does not support incomplete sends. */ +if (status != len) +return -E2BIG ; +return 0 ; }
Re: [PATCH v3 1/2] tpm: Unify the send callback behaviour
In reply to Jarkko SakkinenQuoted 1 line · Jarkko Sakkinen
drivers/char/tpm/st33zp24/st33zp24.c | 2 +-
tpm_ibmvtpm.c needs an update of the description of the send function.
Re: [PATCH v3 1/2] tpm: Unify the send callback behaviour
In reply to Stefan BergerQuoted 22 lines · Stefan Berger
Quoted 6 lines · Jarkko Sakkinen
static void
tpm_nsc_cancel(struct tpm_chip *chip)drivers/char/tpm/tpm_tis_core.c +0
-0drivers/char/tpm/tpm_tis_core.c static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) · line 515
Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +5
-1@@ -507,7 +507,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)if (!priv->irq_tested)disable_interrupts (chip); priv->irq_tested = true; -return rc; + +if (rc <0 ) +return rc; + +return 0 ; }That's not all... There's this above it as well with
tpm_tis_send_mainreturning with 'return len;'.
Quoted 2 lines
if (!(chip->flags &
TPM_CHIP_FLAG_IRQ) ||priv->irq_tested) returntpm_tis_send_main(chip, buf, len);
OK, looks like that your suggestion to do it in *_main() was correct after all.
/Jarkko