[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aVf32R-7LHUACtHY@kernel.org>
Date: Fri, 2 Jan 2026 18:52:41 +0200
From: Jarkko Sakkinen <jarkko@...nel.org>
To: Alper Ak <alperyasinak1@...il.com>
Cc: peterhuewe@....de, Jason Gunthorpe <jgg@...pe.ca>,
James Bottomley <James.Bottomley@...senpartnership.com>,
linux-integrity@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] tpm: tpm2-space: Skip handle check when context load
returns -ENOENT
On Fri, Dec 26, 2025 at 02:12:16PM +0300, Alper Ak wrote:
> When tpm2_load_context() returns -ENOENT, the session is marked as
> forgotten by setting session_tbl[i] to 0. Although tpm2_load_context()
> also sets handle to 0 in this case, the subsequent comparison
> "handle != space->session_tbl[i]" (0 != 0) is always false and serves
> no purpose.
>
> Add continue to skip this unnecessary comparison when load fails with
> -ENOENT, making the control flow clearer and fix possible
> uninitialized 'handle' variable.
>
> Fixes: 4d57856a21ed2 ("tpm2: add session handle context saving and restoring to the space code")
> Signed-off-by: Alper Ak <alperyasinak1@...il.com>
There is no regression here.
> ---
> drivers/char/tpm/tpm2-space.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index 60354cd53b5c..7dfbe07ecf5b 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -213,6 +213,7 @@ static int tpm2_load_space(struct tpm_chip *chip)
> if (rc == -ENOENT) {
> /* load failed, just forget session */
> space->session_tbl[i] = 0;
> + continue;
> } else if (rc) {
> tpm2_flush_space(chip);
> return rc;
> --
> 2.43.0
>
This really does nothing too useful to the code, which we really want
to be conservative to change to begin with.
BR, Jarkko
Powered by blists - more mailing lists