From: Jarkko Sakkinen <jarkko@kernel.org>
To: Jonathan McDowell <noodles@earth.li>
Cc: Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>,
linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/4] tpm: Remove tpm_find_get_ops
Date: Wed, 24 Sep 2025 04:19:03 +0300 [thread overview]
Message-ID: <aNNHBzE3MiAsUkx0@kernel.org> (raw)
In-Reply-To: <99f6216783c4c1c71668ec951cfd8f73bbf93bc6.1758646791.git.noodles@meta.com>
On Tue, Sep 23, 2025 at 06:10:11PM +0100, Jonathan McDowell wrote:
> From: Jonathan McDowell <noodles@meta.com>
>
> tpm_find_get_ops() looks for the first valid TPM if the caller passes in
> NULL. All internal users have been converted to either associate
> themselves with a TPM directly, or call tpm_default_chip() as part of
> their setup. Remove the no longer necessary tpm_find_get_ops().
>
> Signed-off-by: Jonathan McDowell <noodles@meta.com>
This patch fits really well with the changes I've been working on
streamlining some parts (mainly tpm_bufs and sanitizing tpm2-sessions).
I might have ended up doing this type of path myself so I'm glad
it's done.
> ---
> drivers/char/tpm/tpm-chip.c | 36 --------------------------------
> drivers/char/tpm/tpm-interface.c | 20 ++++++++++++++----
> drivers/char/tpm/tpm.h | 1 -
> drivers/char/tpm/tpm_tis_core.c | 3 +--
> 4 files changed, 17 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index 8c8e9054762a..ba906966721a 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -230,42 +230,6 @@ struct tpm_chip *tpm_default_chip(void)
> }
> EXPORT_SYMBOL_GPL(tpm_default_chip);
>
> -/**
> - * tpm_find_get_ops() - find and reserve a TPM chip
> - * @chip: a &struct tpm_chip instance, %NULL for the default chip
> - *
> - * Finds a TPM chip and reserves its class device and operations. The chip must
> - * be released with tpm_put_ops() after use.
> - * This function is for internal use only. It supports existing TPM callers
> - * by accepting NULL, but those callers should be converted to pass in a chip
> - * directly.
> - *
> - * 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_find_get_ops(struct tpm_chip *chip)
> -{
> - int rc;
> -
> - if (chip) {
> - if (!tpm_try_get_ops(chip))
> - return chip;
> - return NULL;
> - }
> -
> - chip = tpm_default_chip();
> - if (!chip)
> - return NULL;
> - rc = tpm_try_get_ops(chip);
> - /* release additional reference we got from tpm_default_chip() */
> - put_device(&chip->dev);
> - if (rc)
> - return NULL;
> - return chip;
> -}
> -
> /**
> * tpm_dev_release() - free chip memory and the device number
> * @dev: the character device for the TPM chip
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index b71725827743..8f65dc06a157 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -313,10 +313,13 @@ int tpm_is_tpm2(struct tpm_chip *chip)
> {
> int rc;
>
> - chip = tpm_find_get_ops(chip);
> if (!chip)
> return -ENODEV;
>
> + rc = tpm_try_get_ops(chip);
> + if (rc)
> + return rc;
> +
> rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0;
>
> tpm_put_ops(chip);
> @@ -338,10 +341,13 @@ int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
> {
> int rc;
>
> - chip = tpm_find_get_ops(chip);
> if (!chip)
> return -ENODEV;
>
> + rc = tpm_try_get_ops(chip);
> + if (rc)
> + return rc;
> +
> if (chip->flags & TPM_CHIP_FLAG_TPM2)
> rc = tpm2_pcr_read(chip, pcr_idx, digest, NULL);
> else
> @@ -369,10 +375,13 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
> int rc;
> int i;
>
> - chip = tpm_find_get_ops(chip);
> if (!chip)
> return -ENODEV;
>
> + rc = tpm_try_get_ops(chip);
> + if (rc)
> + return rc;
> +
> for (i = 0; i < chip->nr_allocated_banks; i++) {
> if (digests[i].alg_id != chip->allocated_banks[i].alg_id) {
> rc = -EINVAL;
> @@ -492,10 +501,13 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
> if (!out || max > TPM_MAX_RNG_DATA)
> return -EINVAL;
>
> - chip = tpm_find_get_ops(chip);
> if (!chip)
> return -ENODEV;
>
> + rc = tpm_try_get_ops(chip);
> + if (rc)
> + return rc;
> +
> if (chip->flags & TPM_CHIP_FLAG_TPM2)
> rc = tpm2_get_random(chip, out, max);
> else
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 7bb87fa5f7a1..9c158c55c05f 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -267,7 +267,6 @@ static inline void tpm_msleep(unsigned int delay_msec)
> int tpm_chip_bootstrap(struct tpm_chip *chip);
> int tpm_chip_start(struct tpm_chip *chip);
> void tpm_chip_stop(struct tpm_chip *chip);
> -struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
>
> struct tpm_chip *tpm_chip_alloc(struct device *dev,
> const struct tpm_class_ops *ops);
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index 4b12c4b9da8b..73b94f4daf4b 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -265,8 +265,7 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
>
> /*
> * Dump stack for forensics, as invalid TPM_STS.x could be
> - * potentially triggered by impaired tpm_try_get_ops() or
> - * tpm_find_get_ops().
> + * potentially triggered by impaired tpm_try_get_ops().
> */
> dump_stack();
> }
> --
> 2.51.0
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
next prev parent reply other threads:[~2025-09-24 1:19 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-02 17:26 [RFC PATCH 0/4] Re-establish ability for exclusive TPM access to userspace Jonathan McDowell
2025-09-02 17:26 ` [RFC PATCH 1/4] tpm: Ensure exclusive userspace access when using /dev/tpm<n> Jonathan McDowell
2025-09-03 19:22 ` Jarkko Sakkinen
2025-09-02 17:27 ` [RFC PATCH 2/4] tpm: Remove tpm_find_get_ops Jonathan McDowell
2025-09-10 16:54 ` Jarkko Sakkinen
2025-09-02 17:27 ` [RFC PATCH 3/4] tpm: Allow for exclusive TPM access when using /dev/tpm<n> Jonathan McDowell
2025-09-10 17:04 ` Jarkko Sakkinen
2025-09-02 17:27 ` [RFC PATCH 4/4] tpm: Require O_EXCL for exclusive /dev/tpm access Jonathan McDowell
2025-09-10 17:06 ` Jarkko Sakkinen
2025-09-23 17:09 ` [PATCH v2 0/4] Re-establish ability for exclusive TPM access to userspace Jonathan McDowell
2025-09-23 17:10 ` [PATCH v2 1/4] tpm: Ensure exclusive userspace access when using /dev/tpm<n> Jonathan McDowell
2025-09-24 1:14 ` Jarkko Sakkinen
2025-09-23 17:10 ` [PATCH v2 2/4] tpm: Remove tpm_find_get_ops Jonathan McDowell
2025-09-24 1:19 ` Jarkko Sakkinen [this message]
2025-09-23 17:10 ` [PATCH v2 3/4] tpm: Allow for exclusive TPM access when using /dev/tpm<n> Jonathan McDowell
2025-09-24 1:22 ` Jarkko Sakkinen
2025-09-23 17:10 ` [PATCH v2 4/4] tpm: Require O_EXCL for exclusive /dev/tpm access Jonathan McDowell
2025-09-24 1:23 ` Jarkko Sakkinen
2025-10-20 11:30 ` [PATCH v3 0/4] pm: Ensure exclusive userspace access when using /dev/tpm<n> Jonathan McDowell
2025-10-20 11:30 ` [PATCH v3 1/4] tpm: Remove tpm_find_get_ops Jonathan McDowell
2025-10-20 11:30 ` [PATCH v3 2/4] tpm: Add O_EXCL for exclusive /dev/tpm access Jonathan McDowell
2025-10-20 11:30 ` [PATCH v3 3/4] tpm: Include /dev/tpmrm<n> when checking exclusive userspace TPM access Jonathan McDowell
2025-10-20 11:31 ` [PATCH v3 4/4] tpm: Allow for exclusive TPM access when using /dev/tpm<n> Jonathan McDowell
2025-10-20 11:53 ` Roberto Sassu
2025-10-23 14:24 ` Jonathan McDowell
2025-10-27 19:38 ` Jarkko Sakkinen
2025-10-27 20:09 ` James Bottomley
2025-10-27 20:18 ` Jarkko Sakkinen
2025-11-03 18:38 ` Jonathan McDowell
2025-11-09 4:34 ` Jarkko Sakkinen
2025-10-24 18:55 ` [PATCH v3 0/4] pm: Ensure exclusive userspace " Jarkko Sakkinen
2025-10-27 11:50 ` Mimi Zohar
2025-10-27 19:41 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aNNHBzE3MiAsUkx0@kernel.org \
--to=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noodles@earth.li \
--cc=peterhuewe@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.