aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/tpm/tpm-interface.c')
-rw-r--r--drivers/char/tpm/tpm-interface.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 17abe52e6365..aaa5fa95dede 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -343,7 +343,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
343 if (count == 0) 343 if (count == 0)
344 return -ENODATA; 344 return -ENODATA;
345 if (count > bufsiz) { 345 if (count > bufsiz) {
346 dev_err(chip->pdev, 346 dev_err(&chip->dev,
347 "invalid count value %x %zx\n", count, bufsiz); 347 "invalid count value %x %zx\n", count, bufsiz);
348 return -E2BIG; 348 return -E2BIG;
349 } 349 }
@@ -353,7 +353,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
353 353
354 rc = chip->ops->send(chip, (u8 *) buf, count); 354 rc = chip->ops->send(chip, (u8 *) buf, count);
355 if (rc < 0) { 355 if (rc < 0) {
356 dev_err(chip->pdev, 356 dev_err(&chip->dev,
357 "tpm_transmit: tpm_send: error %zd\n", rc); 357 "tpm_transmit: tpm_send: error %zd\n", rc);
358 goto out; 358 goto out;
359 } 359 }
@@ -372,7 +372,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
372 goto out_recv; 372 goto out_recv;
373 373
374 if (chip->ops->req_canceled(chip, status)) { 374 if (chip->ops->req_canceled(chip, status)) {
375 dev_err(chip->pdev, "Operation Canceled\n"); 375 dev_err(&chip->dev, "Operation Canceled\n");
376 rc = -ECANCELED; 376 rc = -ECANCELED;
377 goto out; 377 goto out;
378 } 378 }
@@ -382,14 +382,14 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
382 } while (time_before(jiffies, stop)); 382 } while (time_before(jiffies, stop));
383 383
384 chip->ops->cancel(chip); 384 chip->ops->cancel(chip);
385 dev_err(chip->pdev, "Operation Timed out\n"); 385 dev_err(&chip->dev, "Operation Timed out\n");
386 rc = -ETIME; 386 rc = -ETIME;
387 goto out; 387 goto out;
388 388
389out_recv: 389out_recv:
390 rc = chip->ops->recv(chip, (u8 *) buf, bufsiz); 390 rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
391 if (rc < 0) 391 if (rc < 0)
392 dev_err(chip->pdev, 392 dev_err(&chip->dev,
393 "tpm_transmit: tpm_recv: error %zd\n", rc); 393 "tpm_transmit: tpm_recv: error %zd\n", rc);
394out: 394out:
395 if (!(flags & TPM_TRANSMIT_UNLOCKED)) 395 if (!(flags & TPM_TRANSMIT_UNLOCKED))
@@ -416,7 +416,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *cmd,
416 416
417 err = be32_to_cpu(header->return_code); 417 err = be32_to_cpu(header->return_code);
418 if (err != 0 && desc) 418 if (err != 0 && desc)
419 dev_err(chip->pdev, "A TPM error (%d) occurred %s\n", err, 419 dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
420 desc); 420 desc);
421 421
422 return err; 422 return err;
@@ -514,7 +514,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
514 if (rc == TPM_ERR_INVALID_POSTINIT) { 514 if (rc == TPM_ERR_INVALID_POSTINIT) {
515 /* The TPM is not started, we are the first to talk to it. 515 /* The TPM is not started, we are the first to talk to it.
516 Execute a startup command. */ 516 Execute a startup command. */
517 dev_info(chip->pdev, "Issuing TPM_STARTUP"); 517 dev_info(&chip->dev, "Issuing TPM_STARTUP");
518 if (tpm_startup(chip, TPM_ST_CLEAR)) 518 if (tpm_startup(chip, TPM_ST_CLEAR))
519 return rc; 519 return rc;
520 520
@@ -526,7 +526,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
526 0, NULL); 526 0, NULL);
527 } 527 }
528 if (rc) { 528 if (rc) {
529 dev_err(chip->pdev, 529 dev_err(&chip->dev,
530 "A TPM error (%zd) occurred attempting to determine the timeouts\n", 530 "A TPM error (%zd) occurred attempting to determine the timeouts\n",
531 rc); 531 rc);
532 goto duration; 532 goto duration;
@@ -565,7 +565,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
565 565
566 /* Report adjusted timeouts */ 566 /* Report adjusted timeouts */
567 if (chip->vendor.timeout_adjusted) { 567 if (chip->vendor.timeout_adjusted) {
568 dev_info(chip->pdev, 568 dev_info(&chip->dev,
569 HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n", 569 HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n",
570 old_timeout[0], new_timeout[0], 570 old_timeout[0], new_timeout[0],
571 old_timeout[1], new_timeout[1], 571 old_timeout[1], new_timeout[1],
@@ -612,7 +612,7 @@ duration:
612 chip->vendor.duration[TPM_MEDIUM] *= 1000; 612 chip->vendor.duration[TPM_MEDIUM] *= 1000;
613 chip->vendor.duration[TPM_LONG] *= 1000; 613 chip->vendor.duration[TPM_LONG] *= 1000;
614 chip->vendor.duration_adjusted = true; 614 chip->vendor.duration_adjusted = true;
615 dev_info(chip->pdev, "Adjusting TPM timeout parameters."); 615 dev_info(&chip->dev, "Adjusting TPM timeout parameters.");
616 } 616 }
617 return 0; 617 return 0;
618} 618}
@@ -687,7 +687,7 @@ int tpm_is_tpm2(u32 chip_num)
687 687
688 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; 688 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0;
689 689
690 tpm_chip_put(chip); 690 tpm_put_ops(chip);
691 691
692 return rc; 692 return rc;
693} 693}
@@ -716,7 +716,7 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
716 rc = tpm2_pcr_read(chip, pcr_idx, res_buf); 716 rc = tpm2_pcr_read(chip, pcr_idx, res_buf);
717 else 717 else
718 rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf); 718 rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf);
719 tpm_chip_put(chip); 719 tpm_put_ops(chip);
720 return rc; 720 return rc;
721} 721}
722EXPORT_SYMBOL_GPL(tpm_pcr_read); 722EXPORT_SYMBOL_GPL(tpm_pcr_read);
@@ -751,7 +751,7 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
751 751
752 if (chip->flags & TPM_CHIP_FLAG_TPM2) { 752 if (chip->flags & TPM_CHIP_FLAG_TPM2) {
753 rc = tpm2_pcr_extend(chip, pcr_idx, hash); 753 rc = tpm2_pcr_extend(chip, pcr_idx, hash);
754 tpm_chip_put(chip); 754 tpm_put_ops(chip);
755 return rc; 755 return rc;
756 } 756 }
757 757
@@ -761,7 +761,7 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
761 rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE, 0, 761 rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE, 0,
762 "attempting extend a PCR value"); 762 "attempting extend a PCR value");
763 763
764 tpm_chip_put(chip); 764 tpm_put_ops(chip);
765 return rc; 765 return rc;
766} 766}
767EXPORT_SYMBOL_GPL(tpm_pcr_extend); 767EXPORT_SYMBOL_GPL(tpm_pcr_extend);
@@ -802,7 +802,9 @@ int tpm_do_selftest(struct tpm_chip *chip)
802 * around 300ms while the self test is ongoing, keep trying 802 * around 300ms while the self test is ongoing, keep trying
803 * until the self test duration expires. */ 803 * until the self test duration expires. */
804 if (rc == -ETIME) { 804 if (rc == -ETIME) {
805 dev_info(chip->pdev, HW_ERR "TPM command timed out during continue self test"); 805 dev_info(
806 &chip->dev, HW_ERR
807 "TPM command timed out during continue self test");
806 msleep(delay_msec); 808 msleep(delay_msec);
807 continue; 809 continue;
808 } 810 }
@@ -812,7 +814,7 @@ int tpm_do_selftest(struct tpm_chip *chip)
812 814
813 rc = be32_to_cpu(cmd.header.out.return_code); 815 rc = be32_to_cpu(cmd.header.out.return_code);
814 if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) { 816 if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) {
815 dev_info(chip->pdev, 817 dev_info(&chip->dev,
816 "TPM is disabled/deactivated (0x%X)\n", rc); 818 "TPM is disabled/deactivated (0x%X)\n", rc);
817 /* TPM is disabled and/or deactivated; driver can 819 /* TPM is disabled and/or deactivated; driver can
818 * proceed and TPM does handle commands for 820 * proceed and TPM does handle commands for
@@ -840,7 +842,7 @@ int tpm_send(u32 chip_num, void *cmd, size_t buflen)
840 842
841 rc = tpm_transmit_cmd(chip, cmd, buflen, 0, "attempting tpm_cmd"); 843 rc = tpm_transmit_cmd(chip, cmd, buflen, 0, "attempting tpm_cmd");
842 844
843 tpm_chip_put(chip); 845 tpm_put_ops(chip);
844 return rc; 846 return rc;
845} 847}
846EXPORT_SYMBOL_GPL(tpm_send); 848EXPORT_SYMBOL_GPL(tpm_send);
@@ -966,10 +968,10 @@ int tpm_pm_suspend(struct device *dev)
966 } 968 }
967 969
968 if (rc) 970 if (rc)
969 dev_err(chip->pdev, 971 dev_err(&chip->dev,
970 "Error (%d) sending savestate before suspend\n", rc); 972 "Error (%d) sending savestate before suspend\n", rc);
971 else if (try > 0) 973 else if (try > 0)
972 dev_warn(chip->pdev, "TPM savestate took %dms\n", 974 dev_warn(&chip->dev, "TPM savestate took %dms\n",
973 try * TPM_TIMEOUT_RETRY); 975 try * TPM_TIMEOUT_RETRY);
974 976
975 return rc; 977 return rc;
@@ -1023,7 +1025,7 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)
1023 1025
1024 if (chip->flags & TPM_CHIP_FLAG_TPM2) { 1026 if (chip->flags & TPM_CHIP_FLAG_TPM2) {
1025 err = tpm2_get_random(chip, out, max); 1027 err = tpm2_get_random(chip, out, max);
1026 tpm_chip_put(chip); 1028 tpm_put_ops(chip);
1027 return err; 1029 return err;
1028 } 1030 }
1029 1031
@@ -1045,7 +1047,7 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)
1045 num_bytes -= recd; 1047 num_bytes -= recd;
1046 } while (retries-- && total < max); 1048 } while (retries-- && total < max);
1047 1049
1048 tpm_chip_put(chip); 1050 tpm_put_ops(chip);
1049 return total ? total : -EIO; 1051 return total ? total : -EIO;
1050} 1052}
1051EXPORT_SYMBOL_GPL(tpm_get_random); 1053EXPORT_SYMBOL_GPL(tpm_get_random);
@@ -1071,7 +1073,7 @@ int tpm_seal_trusted(u32 chip_num, struct trusted_key_payload *payload,
1071 1073
1072 rc = tpm2_seal_trusted(chip, payload, options); 1074 rc = tpm2_seal_trusted(chip, payload, options);
1073 1075
1074 tpm_chip_put(chip); 1076 tpm_put_ops(chip);
1075 return rc; 1077 return rc;
1076} 1078}
1077EXPORT_SYMBOL_GPL(tpm_seal_trusted); 1079EXPORT_SYMBOL_GPL(tpm_seal_trusted);
@@ -1097,7 +1099,8 @@ int tpm_unseal_trusted(u32 chip_num, struct trusted_key_payload *payload,
1097 1099
1098 rc = tpm2_unseal_trusted(chip, payload, options); 1100 rc = tpm2_unseal_trusted(chip, payload, options);
1099 1101
1100 tpm_chip_put(chip); 1102 tpm_put_ops(chip);
1103
1101 return rc; 1104 return rc;
1102} 1105}
1103EXPORT_SYMBOL_GPL(tpm_unseal_trusted); 1106EXPORT_SYMBOL_GPL(tpm_unseal_trusted);
@@ -1124,6 +1127,7 @@ static int __init tpm_init(void)
1124 1127
1125static void __exit tpm_exit(void) 1128static void __exit tpm_exit(void)
1126{ 1129{
1130 idr_destroy(&dev_nums_idr);
1127 class_destroy(tpm_class); 1131 class_destroy(tpm_class);
1128 unregister_chrdev_region(tpm_devt, TPM_NUM_DEVICES); 1132 unregister_chrdev_region(tpm_devt, TPM_NUM_DEVICES);
1129} 1133}