Skip to content

Commit 93103d5

Browse files
superm1ij-intel
authored andcommitted
platform/x86/amd: pmf: Prevent amd_pmf_tee_deinit() from running twice
If any of the tee init fails, pass up the errors and clear the tee_ctx pointer. This will prevent cleaning up multiple times. Fixes: ac052d8 ("platform/x86/amd/pmf: Add PMF TEE interface") Suggested-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mario Limonciello <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent d9db3a9 commit 93103d5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/platform/x86/amd/pmf/tee-if.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,12 @@ static int amd_pmf_ta_open_session(struct tee_context *ctx, u32 *id, const uuid_
420420
rc = tee_client_open_session(ctx, &sess_arg, NULL);
421421
if (rc < 0 || sess_arg.ret != 0) {
422422
pr_err("Failed to open TEE session err:%#x, rc:%d\n", sess_arg.ret, rc);
423-
return rc;
423+
return rc ?: -EINVAL;
424424
}
425425

426426
*id = sess_arg.session;
427427

428-
return rc;
428+
return 0;
429429
}
430430

431431
static int amd_pmf_register_input_device(struct amd_pmf_dev *dev)
@@ -460,7 +460,9 @@ static int amd_pmf_tee_init(struct amd_pmf_dev *dev, const uuid_t *uuid)
460460
dev->tee_ctx = tee_client_open_context(NULL, amd_pmf_amdtee_ta_match, NULL, NULL);
461461
if (IS_ERR(dev->tee_ctx)) {
462462
dev_err(dev->dev, "Failed to open TEE context\n");
463-
return PTR_ERR(dev->tee_ctx);
463+
ret = PTR_ERR(dev->tee_ctx);
464+
dev->tee_ctx = NULL;
465+
return ret;
464466
}
465467

466468
ret = amd_pmf_ta_open_session(dev->tee_ctx, &dev->session_id, uuid);
@@ -500,9 +502,12 @@ static int amd_pmf_tee_init(struct amd_pmf_dev *dev, const uuid_t *uuid)
500502

501503
static void amd_pmf_tee_deinit(struct amd_pmf_dev *dev)
502504
{
505+
if (!dev->tee_ctx)
506+
return;
503507
tee_shm_free(dev->fw_shm_pool);
504508
tee_client_close_session(dev->tee_ctx, dev->session_id);
505509
tee_client_close_context(dev->tee_ctx);
510+
dev->tee_ctx = NULL;
506511
}
507512

508513
int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev)

0 commit comments

Comments
 (0)