diff options
Diffstat (limited to 'drivers/char/tpm/tpm.c')
-rw-r--r-- | drivers/char/tpm/tpm.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 05ad4a17a28f..2ec5f33cdbd0 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -354,12 +354,14 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, | |||
354 | tpm_protected_ordinal_duration[ordinal & | 354 | tpm_protected_ordinal_duration[ordinal & |
355 | TPM_PROTECTED_ORDINAL_MASK]; | 355 | TPM_PROTECTED_ORDINAL_MASK]; |
356 | 356 | ||
357 | if (duration_idx != TPM_UNDEFINED) | 357 | if (duration_idx != TPM_UNDEFINED) { |
358 | duration = chip->vendor.duration[duration_idx]; | 358 | duration = chip->vendor.duration[duration_idx]; |
359 | if (duration <= 0) | 359 | /* if duration is 0, it's because chip->vendor.duration wasn't */ |
360 | /* filled yet, so we set the lowest timeout just to give enough */ | ||
361 | /* time for tpm_get_timeouts() to succeed */ | ||
362 | return (duration <= 0 ? HZ : duration); | ||
363 | } else | ||
360 | return 2 * 60 * HZ; | 364 | return 2 * 60 * HZ; |
361 | else | ||
362 | return duration; | ||
363 | } | 365 | } |
364 | EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration); | 366 | EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration); |
365 | 367 | ||
@@ -565,9 +567,11 @@ duration: | |||
565 | if (rc) | 567 | if (rc) |
566 | return; | 568 | return; |
567 | 569 | ||
568 | if (be32_to_cpu(tpm_cmd.header.out.return_code) | 570 | if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 || |
569 | != 3 * sizeof(u32)) | 571 | be32_to_cpu(tpm_cmd.header.out.length) |
572 | != sizeof(tpm_cmd.header.out) + sizeof(u32) + 3 * sizeof(u32)) | ||
570 | return; | 573 | return; |
574 | |||
571 | duration_cap = &tpm_cmd.params.getcap_out.cap.duration; | 575 | duration_cap = &tpm_cmd.params.getcap_out.cap.duration; |
572 | chip->vendor.duration[TPM_SHORT] = | 576 | chip->vendor.duration[TPM_SHORT] = |
573 | usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short)); | 577 | usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short)); |
@@ -911,6 +915,18 @@ ssize_t tpm_show_caps_1_2(struct device * dev, | |||
911 | } | 915 | } |
912 | EXPORT_SYMBOL_GPL(tpm_show_caps_1_2); | 916 | EXPORT_SYMBOL_GPL(tpm_show_caps_1_2); |
913 | 917 | ||
918 | ssize_t tpm_show_timeouts(struct device *dev, struct device_attribute *attr, | ||
919 | char *buf) | ||
920 | { | ||
921 | struct tpm_chip *chip = dev_get_drvdata(dev); | ||
922 | |||
923 | return sprintf(buf, "%d %d %d\n", | ||
924 | jiffies_to_usecs(chip->vendor.duration[TPM_SHORT]), | ||
925 | jiffies_to_usecs(chip->vendor.duration[TPM_MEDIUM]), | ||
926 | jiffies_to_usecs(chip->vendor.duration[TPM_LONG])); | ||
927 | } | ||
928 | EXPORT_SYMBOL_GPL(tpm_show_timeouts); | ||
929 | |||
914 | ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, | 930 | ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, |
915 | const char *buf, size_t count) | 931 | const char *buf, size_t count) |
916 | { | 932 | { |