Skip to content

Commit 0c8862d

Browse files
committed
tpm: Re-enable TPM chip boostrapping non-tpm_tis TPM drivers
TPM chip bootstrapping was removed from tpm_chip_register(), and it was relocated to tpm_tis_core. This breaks all drivers which are not based on tpm_tis because the chip will not get properly initialized. Take the corrective steps: 1. Rename tpm_chip_startup() as tpm_chip_bootstrap() and make it one-shot. 2. Call tpm_chip_bootstrap() in tpm_chip_register(), which reverts the things as tehy used to be. Cc: Lino Sanfilippo <[email protected]> Fixes: 548eb51 ("tpm, tpm_tis: startup chip before testing for interrupts") Reported-by: Pengfei Xu <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Tested-by: Pengfei Xu <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 6e98b09 commit 0c8862d

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

drivers/char/tpm/tpm-chip.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,19 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip)
606606
}
607607

608608
/*
609-
* tpm_chip_startup() - performs auto startup and allocates the PCRs
609+
* tpm_chip_bootstrap() - Boostrap TPM chip after power on
610610
* @chip: TPM chip to use.
611+
*
612+
* Initialize TPM chip after power on. This a one-shot function: subsequent
613+
* calls will have no effect.
611614
*/
612-
int tpm_chip_startup(struct tpm_chip *chip)
615+
int tpm_chip_bootstrap(struct tpm_chip *chip)
613616
{
614617
int rc;
615618

619+
if (chip->flags & TPM_CHIP_FLAG_BOOTSTRAPPED)
620+
return 0;
621+
616622
rc = tpm_chip_start(chip);
617623
if (rc)
618624
return rc;
@@ -625,9 +631,15 @@ int tpm_chip_startup(struct tpm_chip *chip)
625631
stop:
626632
tpm_chip_stop(chip);
627633

634+
/*
635+
* Unconditionally set, as driver initialization should cease, when the
636+
* boostrapping process fails.
637+
*/
638+
chip->flags |= TPM_CHIP_FLAG_BOOTSTRAPPED;
639+
628640
return rc;
629641
}
630-
EXPORT_SYMBOL_GPL(tpm_chip_startup);
642+
EXPORT_SYMBOL_GPL(tpm_chip_bootstrap);
631643

632644
/*
633645
* tpm_chip_register() - create a character device for the TPM chip
@@ -644,6 +656,10 @@ int tpm_chip_register(struct tpm_chip *chip)
644656
{
645657
int rc;
646658

659+
rc = tpm_chip_bootstrap(chip);
660+
if (rc)
661+
return rc;
662+
647663
tpm_sysfs_add_device(chip);
648664

649665
tpm_bios_log_setup(chip);

drivers/char/tpm/tpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static inline void tpm_msleep(unsigned int delay_msec)
263263
delay_msec * 1000);
264264
};
265265

266-
int tpm_chip_startup(struct tpm_chip *chip);
266+
int tpm_chip_bootstrap(struct tpm_chip *chip);
267267
int tpm_chip_start(struct tpm_chip *chip);
268268
void tpm_chip_stop(struct tpm_chip *chip);
269269
struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);

drivers/char/tpm/tpm_tis_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
11391139
init_waitqueue_head(&priv->read_queue);
11401140
init_waitqueue_head(&priv->int_queue);
11411141

1142-
rc = tpm_chip_startup(chip);
1142+
rc = tpm_chip_bootstrap(chip);
11431143
if (rc)
11441144
goto out_err;
11451145

include/linux/tpm.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,14 @@ enum tpm2_cc_attrs {
274274
#define TPM_VID_ATML 0x1114
275275

276276
enum tpm_chip_flags {
277-
TPM_CHIP_FLAG_TPM2 = BIT(1),
278-
TPM_CHIP_FLAG_IRQ = BIT(2),
279-
TPM_CHIP_FLAG_VIRTUAL = BIT(3),
280-
TPM_CHIP_FLAG_HAVE_TIMEOUTS = BIT(4),
281-
TPM_CHIP_FLAG_ALWAYS_POWERED = BIT(5),
277+
TPM_CHIP_FLAG_BOOTSTRAPPED = BIT(0),
278+
TPM_CHIP_FLAG_TPM2 = BIT(1),
279+
TPM_CHIP_FLAG_IRQ = BIT(2),
280+
TPM_CHIP_FLAG_VIRTUAL = BIT(3),
281+
TPM_CHIP_FLAG_HAVE_TIMEOUTS = BIT(4),
282+
TPM_CHIP_FLAG_ALWAYS_POWERED = BIT(5),
282283
TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED = BIT(6),
283-
TPM_CHIP_FLAG_FIRMWARE_UPGRADE = BIT(7),
284+
TPM_CHIP_FLAG_FIRMWARE_UPGRADE = BIT(7),
284285
};
285286

286287
#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)

0 commit comments

Comments
 (0)