Unverified Commit 93103d56 authored by Mario Limonciello's avatar Mario Limonciello Committed by Ilpo Järvinen
Browse files

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: ac052d8c ("platform/x86/amd/pmf: Add PMF TEE interface")
Suggested-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/20250512211154.2510397-3-superm1@kernel.org


Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20250522003457.1516679-3-superm1@kernel.org


Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent d9db3a94
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -420,12 +420,12 @@ static int amd_pmf_ta_open_session(struct tee_context *ctx, u32 *id, const uuid_
	rc = tee_client_open_session(ctx, &sess_arg, NULL);
	if (rc < 0 || sess_arg.ret != 0) {
		pr_err("Failed to open TEE session err:%#x, rc:%d\n", sess_arg.ret, rc);
		return rc;
		return rc ?: -EINVAL;
	}

	*id = sess_arg.session;

	return rc;
	return 0;
}

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)
	dev->tee_ctx = tee_client_open_context(NULL, amd_pmf_amdtee_ta_match, NULL, NULL);
	if (IS_ERR(dev->tee_ctx)) {
		dev_err(dev->dev, "Failed to open TEE context\n");
		return PTR_ERR(dev->tee_ctx);
		ret = PTR_ERR(dev->tee_ctx);
		dev->tee_ctx = NULL;
		return ret;
	}

	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)

static void amd_pmf_tee_deinit(struct amd_pmf_dev *dev)
{
	if (!dev->tee_ctx)
		return;
	tee_shm_free(dev->fw_shm_pool);
	tee_client_close_session(dev->tee_ctx, dev->session_id);
	tee_client_close_context(dev->tee_ctx);
	dev->tee_ctx = NULL;
}

int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev)