Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tpm: Implement tpm_default_chip() to find a TPM chip

Implement tpm_default_chip() to find the first TPM chip and return it to
the caller while increasing the reference count on its device. This
function can be used by other subsystems, such as IMA, to find the system's
default TPM chip and use it for all subsequent TPM operations.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

authored by

Stefan Berger and committed by
Jarkko Sakkinen
aaae8153 fc1d52b7

+32
+27
drivers/char/tpm/tpm-chip.c
··· 81 81 EXPORT_SYMBOL_GPL(tpm_put_ops); 82 82 83 83 /** 84 + * tpm_default_chip() - find a TPM chip and get a reference to it 85 + */ 86 + struct tpm_chip *tpm_default_chip(void) 87 + { 88 + struct tpm_chip *chip, *res = NULL; 89 + int chip_num = 0; 90 + int chip_prev; 91 + 92 + mutex_lock(&idr_lock); 93 + 94 + do { 95 + chip_prev = chip_num; 96 + chip = idr_get_next(&dev_nums_idr, &chip_num); 97 + if (chip) { 98 + get_device(&chip->dev); 99 + res = chip; 100 + break; 101 + } 102 + } while (chip_prev != chip_num); 103 + 104 + mutex_unlock(&idr_lock); 105 + 106 + return res; 107 + } 108 + EXPORT_SYMBOL_GPL(tpm_default_chip); 109 + 110 + /** 84 111 * tpm_find_get_ops() - find and reserve a TPM chip 85 112 * @chip: a &struct tpm_chip instance, %NULL for the default chip 86 113 *
+5
include/linux/tpm.h
··· 63 63 extern int tpm_unseal_trusted(struct tpm_chip *chip, 64 64 struct trusted_key_payload *payload, 65 65 struct trusted_key_options *options); 66 + extern struct tpm_chip *tpm_default_chip(void); 66 67 #else 67 68 static inline int tpm_is_tpm2(struct tpm_chip *chip) 68 69 { ··· 98 97 struct trusted_key_options *options) 99 98 { 100 99 return -ENODEV; 100 + } 101 + static inline struct tpm_chip *tpm_default_chip(void) 102 + { 103 + return NULL; 101 104 } 102 105 #endif 103 106 #endif