tpm: invalid self test error message
[cascardo/linux.git] / drivers / char / tpm / tpm2-cmd.c
index a1673dc..0c75c3f 100644 (file)
@@ -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) + \
@@ -854,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;
@@ -894,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
@@ -942,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;
+}