From: Mario Limonciello <superm1@kernel.org>
To: "Shyam Sundar S K" <Shyam-sundar.S-k@amd.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
platform-driver-x86@vger.kernel.org (open list:AMD PMF DRIVER),
Mario Limonciello <mario.limonciello@amd.com>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH v4 2/3] platform/x86/amd: pmf: Prevent amd_pmf_tee_deinit() from running twice
Date: Thu, 15 May 2025 11:23:50 -0500 [thread overview]
Message-ID: <20250515162351.2111468-3-superm1@kernel.org> (raw)
In-Reply-To: <20250515162351.2111468-1-superm1@kernel.org>
From: Mario Limonciello <mario.limonciello@amd.com>
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: ac052d8c08f9d ("platform/x86/amd/pmf: Add PMF TEE interface")
Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/20250512211154.2510397-3-superm1@kernel.org
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/platform/x86/amd/pmf/tee-if.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index 6d85601812225..1b268fffe96e2 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -414,12 +414,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)
@@ -454,7 +454,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);
@@ -494,9 +496,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)
--
2.43.0
next prev parent reply other threads:[~2025-05-15 16:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 16:23 [PATCH v4 0/3] Improved cleanup handling for amd-pmf Mario Limonciello
2025-05-15 16:23 ` [PATCH v4 1/3] platform/x86/amd: pmf: Use device managed allocations Mario Limonciello
2025-05-16 6:04 ` Ilpo Järvinen
2025-05-16 6:20 ` Mario Limonciello
2025-05-16 6:36 ` Ilpo Järvinen
2025-05-16 19:26 ` Mario Limonciello
2025-05-20 15:19 ` Ilpo Järvinen
2025-05-20 15:26 ` Mario Limonciello
2025-05-20 15:34 ` Ilpo Järvinen
2025-05-15 16:23 ` Mario Limonciello [this message]
2025-05-15 16:23 ` [PATCH v4 3/3] platform/x86/amd: pmf: Simplify error flow in amd_pmf_init_smart_pc() Mario Limonciello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250515162351.2111468-3-superm1@kernel.org \
--to=superm1@kernel.org \
--cc=Shyam-sundar.S-k@amd.com \
--cc=dan.carpenter@linaro.org \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=mario.limonciello@amd.com \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox