Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
Hi Jarkko, On 18 January 2018 at 21:50, Jarkko Sakkinen wrote: > On Wed, Jan 17, 2018 at 07:43:51PM +0530, PrasannaKumar Muralidharan wrote: >> Hi Jarkko, >> >> On 14 November 2017 at 20:02, Jarkko Sakkinen >> wrote: >> > On Sun, Nov 12, 2017 at 10:53:35AM +0530, PrasannaKumar Muralidharan wrote: >> >> Did basic check on tpm rng patch, it works fine. As it depends on this >> >> patch this should be working fine too. >> >> >> >> Tested-by: PrasannaKumar Muralidharan >> >> >> >> Regards, >> >> PrasannaKumar >> > >> > Thank you. >> > >> > /Jarkko >> >> Wondering what happened to this and tpm rng patch. Is there something >> more to do for this to get merged? >> >> Thanks, >> PrasannaKumar > > Was part of 4.6 PR. > > /Jarkko Ah, I see. PS: I think you meant 4.16. Thanks, PrasannaKumar
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
On Wed, Jan 17, 2018 at 07:43:51PM +0530, PrasannaKumar Muralidharan wrote: > Hi Jarkko, > > On 14 November 2017 at 20:02, Jarkko Sakkinen > wrote: > > On Sun, Nov 12, 2017 at 10:53:35AM +0530, PrasannaKumar Muralidharan wrote: > >> Did basic check on tpm rng patch, it works fine. As it depends on this > >> patch this should be working fine too. > >> > >> Tested-by: PrasannaKumar Muralidharan > >> > >> Regards, > >> PrasannaKumar > > > > Thank you. > > > > /Jarkko > > Wondering what happened to this and tpm rng patch. Is there something > more to do for this to get merged? > > Thanks, > PrasannaKumar Was part of 4.6 PR. /Jarkko
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
Hi Jarkko, On 14 November 2017 at 20:02, Jarkko Sakkinen wrote: > On Sun, Nov 12, 2017 at 10:53:35AM +0530, PrasannaKumar Muralidharan wrote: >> Did basic check on tpm rng patch, it works fine. As it depends on this >> patch this should be working fine too. >> >> Tested-by: PrasannaKumar Muralidharan >> >> Regards, >> PrasannaKumar > > Thank you. > > /Jarkko Wondering what happened to this and tpm rng patch. Is there something more to do for this to get merged? Thanks, PrasannaKumar
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
On Sun, Nov 12, 2017 at 10:53:35AM +0530, PrasannaKumar Muralidharan wrote: > Did basic check on tpm rng patch, it works fine. As it depends on this > patch this should be working fine too. > > Tested-by: PrasannaKumar Muralidharan > > Regards, > PrasannaKumar Thank you. /Jarkko
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
Did basic check on tpm rng patch, it works fine. As it depends on this patch this should be working fine too. Tested-by: PrasannaKumar Muralidharan Regards, PrasannaKumar
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
On Thu, Oct 26, 2017 at 03:54:50PM +0200, Jarkko Sakkinen wrote: > Device number (the character device index) is not a stable identifier > for a TPM chip. That is the reason why every call site passes > TPM_ANY_NUM to tpm_chip_find_get(). > > This commit changes the API in a way that instead a struct tpm_chip > instance is given and NULL means the default chip. In addition, this > commit refines the documentation to be up to date with the > implementation. > > Suggested-by: Jason Gunthorpe (@chip_num -> > @chip) > Signed-off-by: Jarkko Sakkinen Reviewed-by: Jason Gunthorpe Jason
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
On Thu, Oct 26, 2017 at 09:57:12PM +0530, PrasannaKumar Muralidharan wrote: > I do not what value my rb tag provides as I have not contributed code > to it before. Is it encouraged by kernel community? Yes. People will judge the quality of your rb tag based on other reviews they have seen you make, and here you found a bug, so very good. Got to start someplace. Jason
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
On 26 October 2017 at 21:39, Jarkko Sakkinen wrote: > On Thu, Oct 26, 2017 at 07:40:49PM +0530, PrasannaKumar Muralidharan wrote: >> Hi Jarkko, >> >> On 26 October 2017 at 19:24, Jarkko Sakkinen >> wrote: >> > Device number (the character device index) is not a stable identifier >> > for a TPM chip. That is the reason why every call site passes >> > TPM_ANY_NUM to tpm_chip_find_get(). >> > >> > This commit changes the API in a way that instead a struct tpm_chip >> > instance is given and NULL means the default chip. In addition, this >> > commit refines the documentation to be up to date with the >> > implementation. >> > >> > Suggested-by: Jason Gunthorpe (@chip_num >> > -> @chip) >> > Signed-off-by: Jarkko Sakkinen >> > --- >> > v3: >> > * If chip != NULL was given to tpm_chip_find_get(), it tried to reserve >> > chip >> > associated with the device number 0 instead of trying to reserve the >> > given >> > chip instance. >> > v2: >> > * Further defined function documentation. >> > * Changed @chip_num to @chip instead of removing the parameter as >> > suggested by >> > Jason Gunthorpe. >> > drivers/char/hw_random/tpm-rng.c| 2 +- >> > drivers/char/tpm/tpm-chip.c | 24 --- >> > drivers/char/tpm/tpm-interface.c| 135 >> > +++- >> > drivers/char/tpm/tpm.h | 2 +- >> > include/linux/tpm.h | 38 +- >> > security/integrity/ima/ima_crypto.c | 2 +- >> > security/integrity/ima/ima_init.c | 2 +- >> > security/integrity/ima/ima_queue.c | 2 +- >> > security/keys/trusted.c | 35 +- >> > 9 files changed, 126 insertions(+), 116 deletions(-) >> > >> > diff --git a/drivers/char/hw_random/tpm-rng.c >> > b/drivers/char/hw_random/tpm-rng.c >> > index d6d448266f07..c5e363825af0 100644 >> > --- a/drivers/char/hw_random/tpm-rng.c >> > +++ b/drivers/char/hw_random/tpm-rng.c >> > @@ -25,7 +25,7 @@ >> > >> > static int tpm_rng_read(struct hwrng *rng, void *data, size_t max, bool >> > wait) >> > { >> > - return tpm_get_random(TPM_ANY_NUM, data, max); >> > + return tpm_get_random(NULL, data, max); >> > } >> > >> > static struct hwrng tpm_rng = { >> > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c >> > index a114e8f7fb90..bab9c14e040c 100644 >> > --- a/drivers/char/tpm/tpm-chip.c >> > +++ b/drivers/char/tpm/tpm-chip.c >> > @@ -81,21 +81,26 @@ void tpm_put_ops(struct tpm_chip *chip) >> > EXPORT_SYMBOL_GPL(tpm_put_ops); >> > >> > /** >> > - * tpm_chip_find_get() - return tpm_chip for a given chip number >> > - * @chip_num: id to find >> > + * tpm_chip_find_get() - find and reserve a TPM chip >> > + * @chip: a &struct tpm_chip instance, %NULL for the default chip >> > * >> > - * The return'd chip has been tpm_try_get_ops'd and must be released via >> > - * tpm_put_ops >> > + * Finds a TPM chip and reserves its class device and operations. The >> > chip must >> > + * be released with tpm_chip_put_ops() after use. >> > + * >> > + * Return: >> > + * A reserved &struct tpm_chip instance. >> > + * %NULL if a chip is not found. >> > + * %NULL if the chip is not available. >> > */ >> > -struct tpm_chip *tpm_chip_find_get(int chip_num) >> > +struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip) >> > { >> > - struct tpm_chip *chip, *res = NULL; >> > + struct tpm_chip *res = NULL; >> > + int chip_num = 0; >> > int chip_prev; >> > >> > mutex_lock(&idr_lock); >> > >> > - if (chip_num == TPM_ANY_NUM) { >> > - chip_num = 0; >> > + if (!chip) { >> > do { >> > chip_prev = chip_num; >> > chip = idr_get_next(&dev_nums_idr, &chip_num); >> > @@ -105,8 +110,7 @@ struct tpm_chip *tpm_chip_find_get(int chip_num) >> > } >> > } while (chip_prev != chip_num); >> > } else { >> > - chip = idr_find(&dev_nums_idr, chip_num); >> > - if (chip && !tpm_try_get_ops(chip)) >> > + if (!tpm_try_get_ops(chip)) >> > res = chip; >> > } >> > >> > diff --git a/drivers/char/tpm/tpm-interface.c >> > b/drivers/char/tpm/tpm-interface.c >> > index ebe0a1d36d8c..19f820f775b5 100644 >> > --- a/drivers/char/tpm/tpm-interface.c >> > +++ b/drivers/char/tpm/tpm-interface.c >> > @@ -809,19 +809,20 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int >> > pcr_idx, u8 *res_buf) >> > } >> > >> > /** >> > - * tpm_is_tpm2 - is the chip a TPM2 chip? >> > - * @chip_num: tpm idx # or ANY >> > + * tpm_is_tpm2 - do we a have a TPM2 chip? >> > + * @chip: a &struct tpm_chip instance, %NULL for the default chip >> > * >> > - * Returns < 0 on error, and 1 or 0 on success depending whether the chip >> > - * is a TPM2 chip. >> > + * Return: >> > + * 1 if we have a TPM2 chip. >> > + * 0 if we don't have a TPM2 chip. >> > + * A negative number for system err
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
On Thu, Oct 26, 2017 at 07:40:49PM +0530, PrasannaKumar Muralidharan wrote: > Hi Jarkko, > > On 26 October 2017 at 19:24, Jarkko Sakkinen > wrote: > > Device number (the character device index) is not a stable identifier > > for a TPM chip. That is the reason why every call site passes > > TPM_ANY_NUM to tpm_chip_find_get(). > > > > This commit changes the API in a way that instead a struct tpm_chip > > instance is given and NULL means the default chip. In addition, this > > commit refines the documentation to be up to date with the > > implementation. > > > > Suggested-by: Jason Gunthorpe (@chip_num > > -> @chip) > > Signed-off-by: Jarkko Sakkinen > > --- > > v3: > > * If chip != NULL was given to tpm_chip_find_get(), it tried to reserve chip > > associated with the device number 0 instead of trying to reserve the given > > chip instance. > > v2: > > * Further defined function documentation. > > * Changed @chip_num to @chip instead of removing the parameter as suggested > > by > > Jason Gunthorpe. > > drivers/char/hw_random/tpm-rng.c| 2 +- > > drivers/char/tpm/tpm-chip.c | 24 --- > > drivers/char/tpm/tpm-interface.c| 135 > > +++- > > drivers/char/tpm/tpm.h | 2 +- > > include/linux/tpm.h | 38 +- > > security/integrity/ima/ima_crypto.c | 2 +- > > security/integrity/ima/ima_init.c | 2 +- > > security/integrity/ima/ima_queue.c | 2 +- > > security/keys/trusted.c | 35 +- > > 9 files changed, 126 insertions(+), 116 deletions(-) > > > > diff --git a/drivers/char/hw_random/tpm-rng.c > > b/drivers/char/hw_random/tpm-rng.c > > index d6d448266f07..c5e363825af0 100644 > > --- a/drivers/char/hw_random/tpm-rng.c > > +++ b/drivers/char/hw_random/tpm-rng.c > > @@ -25,7 +25,7 @@ > > > > static int tpm_rng_read(struct hwrng *rng, void *data, size_t max, bool > > wait) > > { > > - return tpm_get_random(TPM_ANY_NUM, data, max); > > + return tpm_get_random(NULL, data, max); > > } > > > > static struct hwrng tpm_rng = { > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c > > index a114e8f7fb90..bab9c14e040c 100644 > > --- a/drivers/char/tpm/tpm-chip.c > > +++ b/drivers/char/tpm/tpm-chip.c > > @@ -81,21 +81,26 @@ void tpm_put_ops(struct tpm_chip *chip) > > EXPORT_SYMBOL_GPL(tpm_put_ops); > > > > /** > > - * tpm_chip_find_get() - return tpm_chip for a given chip number > > - * @chip_num: id to find > > + * tpm_chip_find_get() - find and reserve a TPM chip > > + * @chip: a &struct tpm_chip instance, %NULL for the default chip > > * > > - * The return'd chip has been tpm_try_get_ops'd and must be released via > > - * tpm_put_ops > > + * Finds a TPM chip and reserves its class device and operations. The chip > > must > > + * be released with tpm_chip_put_ops() after use. > > + * > > + * Return: > > + * A reserved &struct tpm_chip instance. > > + * %NULL if a chip is not found. > > + * %NULL if the chip is not available. > > */ > > -struct tpm_chip *tpm_chip_find_get(int chip_num) > > +struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip) > > { > > - struct tpm_chip *chip, *res = NULL; > > + struct tpm_chip *res = NULL; > > + int chip_num = 0; > > int chip_prev; > > > > mutex_lock(&idr_lock); > > > > - if (chip_num == TPM_ANY_NUM) { > > - chip_num = 0; > > + if (!chip) { > > do { > > chip_prev = chip_num; > > chip = idr_get_next(&dev_nums_idr, &chip_num); > > @@ -105,8 +110,7 @@ struct tpm_chip *tpm_chip_find_get(int chip_num) > > } > > } while (chip_prev != chip_num); > > } else { > > - chip = idr_find(&dev_nums_idr, chip_num); > > - if (chip && !tpm_try_get_ops(chip)) > > + if (!tpm_try_get_ops(chip)) > > res = chip; > > } > > > > diff --git a/drivers/char/tpm/tpm-interface.c > > b/drivers/char/tpm/tpm-interface.c > > index ebe0a1d36d8c..19f820f775b5 100644 > > --- a/drivers/char/tpm/tpm-interface.c > > +++ b/drivers/char/tpm/tpm-interface.c > > @@ -809,19 +809,20 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int > > pcr_idx, u8 *res_buf) > > } > > > > /** > > - * tpm_is_tpm2 - is the chip a TPM2 chip? > > - * @chip_num: tpm idx # or ANY > > + * tpm_is_tpm2 - do we a have a TPM2 chip? > > + * @chip: a &struct tpm_chip instance, %NULL for the default chip > > * > > - * Returns < 0 on error, and 1 or 0 on success depending whether the chip > > - * is a TPM2 chip. > > + * Return: > > + * 1 if we have a TPM2 chip. > > + * 0 if we don't have a TPM2 chip. > > + * A negative number for system errors (errno). > > */ > > -int tpm_is_tpm2(u32 chip_num) > > +int tpm_is_tpm2(struct tpm_chip *chip) > > { > > - struct tpm_chip *chip; > > int rc; > > > > - chip = tpm_
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
Hi Jarkko, On 26 October 2017 at 19:24, Jarkko Sakkinen wrote: > Device number (the character device index) is not a stable identifier > for a TPM chip. That is the reason why every call site passes > TPM_ANY_NUM to tpm_chip_find_get(). > > This commit changes the API in a way that instead a struct tpm_chip > instance is given and NULL means the default chip. In addition, this > commit refines the documentation to be up to date with the > implementation. > > Suggested-by: Jason Gunthorpe (@chip_num -> > @chip) > Signed-off-by: Jarkko Sakkinen > --- > v3: > * If chip != NULL was given to tpm_chip_find_get(), it tried to reserve chip > associated with the device number 0 instead of trying to reserve the given > chip instance. > v2: > * Further defined function documentation. > * Changed @chip_num to @chip instead of removing the parameter as suggested by > Jason Gunthorpe. > drivers/char/hw_random/tpm-rng.c| 2 +- > drivers/char/tpm/tpm-chip.c | 24 --- > drivers/char/tpm/tpm-interface.c| 135 > +++- > drivers/char/tpm/tpm.h | 2 +- > include/linux/tpm.h | 38 +- > security/integrity/ima/ima_crypto.c | 2 +- > security/integrity/ima/ima_init.c | 2 +- > security/integrity/ima/ima_queue.c | 2 +- > security/keys/trusted.c | 35 +- > 9 files changed, 126 insertions(+), 116 deletions(-) > > diff --git a/drivers/char/hw_random/tpm-rng.c > b/drivers/char/hw_random/tpm-rng.c > index d6d448266f07..c5e363825af0 100644 > --- a/drivers/char/hw_random/tpm-rng.c > +++ b/drivers/char/hw_random/tpm-rng.c > @@ -25,7 +25,7 @@ > > static int tpm_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) > { > - return tpm_get_random(TPM_ANY_NUM, data, max); > + return tpm_get_random(NULL, data, max); > } > > static struct hwrng tpm_rng = { > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c > index a114e8f7fb90..bab9c14e040c 100644 > --- a/drivers/char/tpm/tpm-chip.c > +++ b/drivers/char/tpm/tpm-chip.c > @@ -81,21 +81,26 @@ void tpm_put_ops(struct tpm_chip *chip) > EXPORT_SYMBOL_GPL(tpm_put_ops); > > /** > - * tpm_chip_find_get() - return tpm_chip for a given chip number > - * @chip_num: id to find > + * tpm_chip_find_get() - find and reserve a TPM chip > + * @chip: a &struct tpm_chip instance, %NULL for the default chip > * > - * The return'd chip has been tpm_try_get_ops'd and must be released via > - * tpm_put_ops > + * Finds a TPM chip and reserves its class device and operations. The chip > must > + * be released with tpm_chip_put_ops() after use. > + * > + * Return: > + * A reserved &struct tpm_chip instance. > + * %NULL if a chip is not found. > + * %NULL if the chip is not available. > */ > -struct tpm_chip *tpm_chip_find_get(int chip_num) > +struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip) > { > - struct tpm_chip *chip, *res = NULL; > + struct tpm_chip *res = NULL; > + int chip_num = 0; > int chip_prev; > > mutex_lock(&idr_lock); > > - if (chip_num == TPM_ANY_NUM) { > - chip_num = 0; > + if (!chip) { > do { > chip_prev = chip_num; > chip = idr_get_next(&dev_nums_idr, &chip_num); > @@ -105,8 +110,7 @@ struct tpm_chip *tpm_chip_find_get(int chip_num) > } > } while (chip_prev != chip_num); > } else { > - chip = idr_find(&dev_nums_idr, chip_num); > - if (chip && !tpm_try_get_ops(chip)) > + if (!tpm_try_get_ops(chip)) > res = chip; > } > > diff --git a/drivers/char/tpm/tpm-interface.c > b/drivers/char/tpm/tpm-interface.c > index ebe0a1d36d8c..19f820f775b5 100644 > --- a/drivers/char/tpm/tpm-interface.c > +++ b/drivers/char/tpm/tpm-interface.c > @@ -809,19 +809,20 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int > pcr_idx, u8 *res_buf) > } > > /** > - * tpm_is_tpm2 - is the chip a TPM2 chip? > - * @chip_num: tpm idx # or ANY > + * tpm_is_tpm2 - do we a have a TPM2 chip? > + * @chip: a &struct tpm_chip instance, %NULL for the default chip > * > - * Returns < 0 on error, and 1 or 0 on success depending whether the chip > - * is a TPM2 chip. > + * Return: > + * 1 if we have a TPM2 chip. > + * 0 if we don't have a TPM2 chip. > + * A negative number for system errors (errno). > */ > -int tpm_is_tpm2(u32 chip_num) > +int tpm_is_tpm2(struct tpm_chip *chip) > { > - struct tpm_chip *chip; > int rc; > > - chip = tpm_chip_find_get(chip_num); > - if (chip == NULL) > + chip = tpm_chip_find_get(chip); > + if (!chip) > return -ENODEV; > > rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; > @@ -833,23 +834,19 @@ int tpm_is_tpm2(u32 chip_num) > EXPORT_SYMBOL_GPL(tpm_is_tpm2); > > /** > - * tpm_pcr_read - read a pcr value >
Re: [PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
On Thu, Oct 26, 2017 at 03:54:50PM +0200, Jarkko Sakkinen wrote: > Device number (the character device index) is not a stable identifier > for a TPM chip. That is the reason why every call site passes > TPM_ANY_NUM to tpm_chip_find_get(). > > This commit changes the API in a way that instead a struct tpm_chip > instance is given and NULL means the default chip. In addition, this > commit refines the documentation to be up to date with the > implementation. > > Suggested-by: Jason Gunthorpe (@chip_num -> > @chip) > Signed-off-by: Jarkko Sakkinen Jason, once you have given this reviewed-by can you do a patch set that includes this and your and PrasannaKumar's change? It could be a while before keyring and IMA maintainers have reviewed my change. /Jarkko
[PATCH v3] tpm: use struct tpm_chip for tpm_chip_find_get()
Device number (the character device index) is not a stable identifier for a TPM chip. That is the reason why every call site passes TPM_ANY_NUM to tpm_chip_find_get(). This commit changes the API in a way that instead a struct tpm_chip instance is given and NULL means the default chip. In addition, this commit refines the documentation to be up to date with the implementation. Suggested-by: Jason Gunthorpe (@chip_num -> @chip) Signed-off-by: Jarkko Sakkinen --- v3: * If chip != NULL was given to tpm_chip_find_get(), it tried to reserve chip associated with the device number 0 instead of trying to reserve the given chip instance. v2: * Further defined function documentation. * Changed @chip_num to @chip instead of removing the parameter as suggested by Jason Gunthorpe. drivers/char/hw_random/tpm-rng.c| 2 +- drivers/char/tpm/tpm-chip.c | 24 --- drivers/char/tpm/tpm-interface.c| 135 +++- drivers/char/tpm/tpm.h | 2 +- include/linux/tpm.h | 38 +- security/integrity/ima/ima_crypto.c | 2 +- security/integrity/ima/ima_init.c | 2 +- security/integrity/ima/ima_queue.c | 2 +- security/keys/trusted.c | 35 +- 9 files changed, 126 insertions(+), 116 deletions(-) diff --git a/drivers/char/hw_random/tpm-rng.c b/drivers/char/hw_random/tpm-rng.c index d6d448266f07..c5e363825af0 100644 --- a/drivers/char/hw_random/tpm-rng.c +++ b/drivers/char/hw_random/tpm-rng.c @@ -25,7 +25,7 @@ static int tpm_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) { - return tpm_get_random(TPM_ANY_NUM, data, max); + return tpm_get_random(NULL, data, max); } static struct hwrng tpm_rng = { diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index a114e8f7fb90..bab9c14e040c 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -81,21 +81,26 @@ void tpm_put_ops(struct tpm_chip *chip) EXPORT_SYMBOL_GPL(tpm_put_ops); /** - * tpm_chip_find_get() - return tpm_chip for a given chip number - * @chip_num: id to find + * tpm_chip_find_get() - find and reserve a TPM chip + * @chip: a &struct tpm_chip instance, %NULL for the default chip * - * The return'd chip has been tpm_try_get_ops'd and must be released via - * tpm_put_ops + * Finds a TPM chip and reserves its class device and operations. The chip must + * be released with tpm_chip_put_ops() after use. + * + * Return: + * A reserved &struct tpm_chip instance. + * %NULL if a chip is not found. + * %NULL if the chip is not available. */ -struct tpm_chip *tpm_chip_find_get(int chip_num) +struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip) { - struct tpm_chip *chip, *res = NULL; + struct tpm_chip *res = NULL; + int chip_num = 0; int chip_prev; mutex_lock(&idr_lock); - if (chip_num == TPM_ANY_NUM) { - chip_num = 0; + if (!chip) { do { chip_prev = chip_num; chip = idr_get_next(&dev_nums_idr, &chip_num); @@ -105,8 +110,7 @@ struct tpm_chip *tpm_chip_find_get(int chip_num) } } while (chip_prev != chip_num); } else { - chip = idr_find(&dev_nums_idr, chip_num); - if (chip && !tpm_try_get_ops(chip)) + if (!tpm_try_get_ops(chip)) res = chip; } diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index ebe0a1d36d8c..19f820f775b5 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -809,19 +809,20 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) } /** - * tpm_is_tpm2 - is the chip a TPM2 chip? - * @chip_num: tpm idx # or ANY + * tpm_is_tpm2 - do we a have a TPM2 chip? + * @chip: a &struct tpm_chip instance, %NULL for the default chip * - * Returns < 0 on error, and 1 or 0 on success depending whether the chip - * is a TPM2 chip. + * Return: + * 1 if we have a TPM2 chip. + * 0 if we don't have a TPM2 chip. + * A negative number for system errors (errno). */ -int tpm_is_tpm2(u32 chip_num) +int tpm_is_tpm2(struct tpm_chip *chip) { - struct tpm_chip *chip; int rc; - chip = tpm_chip_find_get(chip_num); - if (chip == NULL) + chip = tpm_chip_find_get(chip); + if (!chip) return -ENODEV; rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; @@ -833,23 +834,19 @@ int tpm_is_tpm2(u32 chip_num) EXPORT_SYMBOL_GPL(tpm_is_tpm2); /** - * tpm_pcr_read - read a pcr value - * @chip_num: tpm idx # or ANY - * @pcr_idx: pcr idx to retrieve - * @res_buf: TPM_PCR value - * size of res_buf is 20 bytes (or NULL if you don't care) + * tpm_pcr_read - read a PCR value from SHA1 bank + * @chip: a &struct tpm_chip instance, %NULL for the default chip + * @pcr_idx: the PCR to b