]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
platform/x86/amd: pmf: Prevent amd_pmf_tee_deinit() from running twice
authorMario Limonciello <mario.limonciello@amd.com>
Thu, 22 May 2025 00:34:56 +0000 (19:34 -0500)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 10 Jun 2025 07:42:14 +0000 (10:42 +0300)
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>
Link: https://lore.kernel.org/r/20250522003457.1516679-3-superm1@kernel.org
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/amd/pmf/tee-if.c

index 027e992b71472284564f35cfc999bd07cca86c10..76efce48a45ce2aa180d7f8794b161cc5b096313 100644 (file)
@@ -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 @@ out_ctx:
 
 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)