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 <[email protected]>
---
 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


Reply via email to