]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
tpm: Unify the send callback behaviour
authorJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Fri, 8 Feb 2019 16:30:58 +0000 (18:30 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837952
commit f5595f5baa30e009bf54d0d7653a9a0cc465be60 upstream.

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.

Suggested-by: Stefan Berger <stefanb@linux.ibm.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
12 files changed:
drivers/char/tpm/st33zp24/st33zp24.c
drivers/char/tpm/tpm-interface.c
drivers/char/tpm/tpm_atmel.c
drivers/char/tpm/tpm_i2c_atmel.c
drivers/char/tpm/tpm_i2c_infineon.c
drivers/char/tpm/tpm_i2c_nuvoton.c
drivers/char/tpm/tpm_ibmvtpm.c
drivers/char/tpm/tpm_infineon.c
drivers/char/tpm/tpm_nsc.c
drivers/char/tpm/tpm_tis_core.c
drivers/char/tpm/tpm_vtpm_proxy.c
drivers/char/tpm/xen-tpmfront.c

index f95b9c75175bcf27825b16891ca405886e51c379..77f3fa10db1209f7b7703d4eb9bef972f6b60298 100644 (file)
@@ -438,7 +438,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);
index 1c0a3d3da8e68c8101c3e27d3ab0e4eeaa1282fc..52e95b2448387fc19859307fa3487b070dc58f61 100644 (file)
@@ -497,10 +497,19 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
        if (rc < 0) {
                if (rc != -EPIPE)
                        dev_err(&chip->dev,
-                               "%s: tpm_send: error %d\n", __func__, rc);
+                               "%s: send(): error %d\n", __func__, rc);
                goto out;
        }
 
+       /* A sanity check. send() should just return zero on success e.g.
+        * not the command length.
+        */
+       if (rc > 0) {
+               dev_warn(&chip->dev,
+                        "%s: send(): invalid value %d\n", __func__, rc);
+               rc = 0;
+       }
+
        if (chip->flags & TPM_CHIP_FLAG_IRQ)
                goto out_recv;
 
index 66a14526aaf4c811f7f15d0bd94c195ab2dabd3e..a290b30a0c3570b11db5a81b7369e331adc66c34 100644 (file)
@@ -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)
index 95ce2e9ccdc6e2ec40c7d52b0f35d17ba260001e..32a8e27c5382fe2677393e9f47f5055f1013c163 100644 (file)
@@ -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)
index c619e76ce827615caa2c47bd6d6abbb368f8a416..94bdb8ec372e3813cb02138b59d21c6ab5b0c06d 100644 (file)
@@ -587,7 +587,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,
index f74f451baf6ae039a8599b8a14da4ee398e387d1..b8defdfdf2dc6e3bac94bcf9b02d036d5d9cba7d 100644 (file)
@@ -469,7 +469,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)
index 25f6e2665385d063d47c50ad9f21e25591f828c9..77e47dc5aacc5705b465583d2c02f26f8b393d56 100644 (file)
@@ -141,14 +141,14 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 }
 
 /**
- * tpm_ibmvtpm_send - Send tpm request
- *
+ * tpm_ibmvtpm_send() - Send a TPM command
  * @chip:      tpm chip struct
  * @buf:       buffer contains data to send
  * @count:     size of buffer
  *
  * Return:
- *     Number of bytes sent or < 0 on error.
+ *   0 on success,
+ *   -errno on error
  */
 static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
 {
@@ -194,7 +194,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;
index d8f10047fbbaf1f2f965a795358e60be859fb759..97f6d4fe0aee14d8a49d88480f7b78bb84462f67 100644 (file)
@@ -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)
index 5d6cce74cd3fa3e7f71cf207454dd1e5e492e560..9bee3c5eb4bf342dc41cfdd29d1a6f01ee4a67ca 100644 (file)
@@ -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)
index 6f54fa66f18266b4533c5f29f6d9bd98830f8a99..ba8c1d73e0bc0f51a77892db64f9d0a72a7244fb 100644 (file)
@@ -379,7 +379,7 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
                        goto out_err;
                }
        }
-       return len;
+       return 0;
 out_err:
        tpm_tis_ready(chip);
        return rc;
index 1d877cc9af97d471e827b61d081f5c49bfa666c7..94a539384619bcae4c697de65edc7fe75263e562 100644 (file)
@@ -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)
index 2cffaf567d9960c1dda0519158ab2a6d3fdcdad8..538c9297dee18218b9bc0dd6029e3748a6401617 100644 (file)
@@ -112,7 +112,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)