Merge tag 'tpmdd-v6.4-rc1-fix-v2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / drivers / char / tpm / tpm-chip.c
index 80aaa10f436ec8de0ed9ace56a1d4f678a983427..c10a4aa9737366f949d3fb0602971ef85ae3d5a6 100644 (file)
@@ -605,13 +605,19 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip)
 }
 
 /*
- * tpm_chip_startup() - performs auto startup and allocates the PCRs
+ * tpm_chip_bootstrap() - Boostrap TPM chip after power on
  * @chip: TPM chip to use.
+ *
+ * Initialize TPM chip after power on. This a one-shot function: subsequent
+ * calls will have no effect.
  */
-int tpm_chip_startup(struct tpm_chip *chip)
+int tpm_chip_bootstrap(struct tpm_chip *chip)
 {
        int rc;
 
+       if (chip->flags & TPM_CHIP_FLAG_BOOTSTRAPPED)
+               return 0;
+
        rc = tpm_chip_start(chip);
        if (rc)
                return rc;
@@ -624,9 +630,15 @@ int tpm_chip_startup(struct tpm_chip *chip)
 stop:
        tpm_chip_stop(chip);
 
+       /*
+        * Unconditionally set, as driver initialization should cease, when the
+        * boostrapping process fails.
+        */
+       chip->flags |= TPM_CHIP_FLAG_BOOTSTRAPPED;
+
        return rc;
 }
-EXPORT_SYMBOL_GPL(tpm_chip_startup);
+EXPORT_SYMBOL_GPL(tpm_chip_bootstrap);
 
 /*
  * tpm_chip_register() - create a character device for the TPM chip
@@ -643,6 +655,10 @@ int tpm_chip_register(struct tpm_chip *chip)
 {
        int rc;
 
+       rc = tpm_chip_bootstrap(chip);
+       if (rc)
+               return rc;
+
        tpm_sysfs_add_device(chip);
 
        tpm_bios_log_setup(chip);