tpm: invalid self test error message
[cascardo/linux.git] / drivers / char / tpm / tpm2-cmd.c
index b28e4da..0c75c3f 100644 (file)
@@ -597,7 +597,7 @@ static void tpm2_flush_context(struct tpm_chip *chip, u32 handle)
 
        rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_FLUSH_CONTEXT);
        if (rc) {
-               dev_warn(chip->pdev, "0x%08x was not flushed, out of memory\n",
+               dev_warn(&chip->dev, "0x%08x was not flushed, out of memory\n",
                         handle);
                return;
        }
@@ -606,7 +606,7 @@ static void tpm2_flush_context(struct tpm_chip *chip, u32 handle)
 
        rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, "flushing context");
        if (rc)
-               dev_warn(chip->pdev, "0x%08x was not flushed, rc=%d\n", handle,
+               dev_warn(&chip->dev, "0x%08x was not flushed, rc=%d\n", handle,
                         rc);
 
        tpm_buf_destroy(&buf);
@@ -703,7 +703,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
 
        rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), desc);
        if (!rc)
-               *value = cmd.params.get_tpm_pt_out.value;
+               *value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);
 
        return rc;
 }
@@ -728,7 +728,7 @@ static const struct tpm_input_header tpm2_startup_header = {
  * returned it remarks a POSIX error code. If a positive number is returned
  * it remarks a TPM error.
  */
-int tpm2_startup(struct tpm_chip *chip, u16 startup_type)
+static int tpm2_startup(struct tpm_chip *chip, u16 startup_type)
 {
        struct tpm2_cmd cmd;
 
@@ -738,7 +738,6 @@ int tpm2_startup(struct tpm_chip *chip, u16 startup_type)
        return tpm_transmit_cmd(chip, &cmd, sizeof(cmd),
                                "attempting to start the TPM");
 }
-EXPORT_SYMBOL_GPL(tpm2_startup);
 
 #define TPM2_SHUTDOWN_IN_SIZE \
        (sizeof(struct tpm_input_header) + \
@@ -770,10 +769,9 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type)
         * except print the error code on a system failure.
         */
        if (rc < 0)
-               dev_warn(chip->pdev, "transmit returned %d while stopping the TPM",
+               dev_warn(&chip->dev, "transmit returned %d while stopping the TPM",
                         rc);
 }
-EXPORT_SYMBOL_GPL(tpm2_shutdown);
 
 /*
  * tpm2_calc_ordinal_duration() - maximum duration for a command
@@ -793,7 +791,7 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
                index = tpm2_ordinal_duration[ordinal - TPM2_CC_FIRST];
 
        if (index != TPM_UNDEFINED)
-               duration = chip->vendor.duration[index];
+               duration = chip->duration[index];
 
        if (duration <= 0)
                duration = 2 * 60 * HZ;
@@ -837,7 +835,7 @@ static int tpm2_start_selftest(struct tpm_chip *chip, bool full)
         * immediately. This is a workaround for that.
         */
        if (rc == TPM2_RC_TESTING) {
-               dev_warn(chip->pdev, "Got RC_TESTING, ignoring\n");
+               dev_warn(&chip->dev, "Got RC_TESTING, ignoring\n");
                rc = 0;
        }
 
@@ -855,7 +853,7 @@ static int tpm2_start_selftest(struct tpm_chip *chip, bool full)
  * returned it remarks a POSIX error code. If a positive number is returned
  * it remarks a TPM error.
  */
-int tpm2_do_selftest(struct tpm_chip *chip)
+static int tpm2_do_selftest(struct tpm_chip *chip)
 {
        int rc;
        unsigned int loops;
@@ -895,7 +893,6 @@ int tpm2_do_selftest(struct tpm_chip *chip)
 
        return rc;
 }
-EXPORT_SYMBOL_GPL(tpm2_do_selftest);
 
 /**
  * tpm2_gen_interrupt() - generate an interrupt
@@ -943,3 +940,42 @@ int tpm2_probe(struct tpm_chip *chip)
        return 0;
 }
 EXPORT_SYMBOL_GPL(tpm2_probe);
+
+/**
+ * tpm2_auto_startup - Perform the standard automatic TPM initialization
+ *                     sequence
+ * @chip: TPM chip to use
+ *
+ * Returns 0 on success, < 0 in case of fatal error.
+ */
+int tpm2_auto_startup(struct tpm_chip *chip)
+{
+       int rc;
+
+       rc = tpm_get_timeouts(chip);
+       if (rc)
+               goto out;
+
+       rc = tpm2_do_selftest(chip);
+       if (rc != 0 && rc != TPM2_RC_INITIALIZE) {
+               dev_err(&chip->dev, "TPM self test failed\n");
+               goto out;
+       }
+
+       if (rc == TPM2_RC_INITIALIZE) {
+               rc = tpm2_startup(chip, TPM2_SU_CLEAR);
+               if (rc)
+                       goto out;
+
+               rc = tpm2_do_selftest(chip);
+               if (rc) {
+                       dev_err(&chip->dev, "TPM self test failed\n");
+                       goto out;
+               }
+       }
+
+out:
+       if (rc > 0)
+               rc = -ENODEV;
+       return rc;
+}