linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm: tpm2-space: Skip handle check when context load returns -ENOENT
@ 2025-12-26 11:12 Alper Ak
  2026-01-02 16:52 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Alper Ak @ 2025-12-26 11:12 UTC (permalink / raw)
  To: peterhuewe, jarkko
  Cc: Alper Ak, Jason Gunthorpe, James Bottomley, linux-integrity,
	linux-kernel

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tpm: tpm2-space: Skip handle check when context load returns -ENOENT
  2025-12-26 11:12 [PATCH] tpm: tpm2-space: Skip handle check when context load returns -ENOENT Alper Ak
@ 2026-01-02 16:52 ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2026-01-02 16:52 UTC (permalink / raw)
  To: Alper Ak
  Cc: peterhuewe, Jason Gunthorpe, James Bottomley, linux-integrity,
	linux-kernel

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@gmail.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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-02 16:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-26 11:12 [PATCH] tpm: tpm2-space: Skip handle check when context load returns -ENOENT Alper Ak
2026-01-02 16:52 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).