Skip to content

Commit 65fa3a3

Browse files
jenswi-linarojforissier
authored andcommitted
tee: optee: fix device enumeration error handling
Prior to this patch in optee_probe() when optee_enumerate_devices() was called the struct optee was fully initialized. If optee_enumerate_devices() returns an error optee_probe() is supposed to clean up and free the struct optee completely, but will at this late stage need to call optee_remove() instead. This isn't done and thus freeing the struct optee prematurely. With this patch the call to optee_enumerate_devices() is done after optee_probe() has returned successfully and in case optee_enumerate_devices() fails everything is cleaned up with a call to optee_remove(). Fixes: c3fa24a ("tee: optee: add TEE bus device enumeration support") Reviewed-by: Sumit Garg <[email protected]> Signed-off-by: Jens Wiklander <[email protected]>
1 parent a37a13f commit 65fa3a3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/tee/optee/core.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,6 @@ static struct optee *optee_probe(struct device_node *np)
653653
if (optee->sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM)
654654
pr_info("dynamic shared memory is enabled\n");
655655

656-
rc = optee_enumerate_devices();
657-
if (rc)
658-
goto err;
659-
660-
pr_info("initialized driver\n");
661656
return optee;
662657
err:
663658
if (optee) {
@@ -712,9 +707,10 @@ static struct optee *optee_svc;
712707

713708
static int __init optee_driver_init(void)
714709
{
715-
struct device_node *fw_np;
716-
struct device_node *np;
717-
struct optee *optee;
710+
struct device_node *fw_np = NULL;
711+
struct device_node *np = NULL;
712+
struct optee *optee = NULL;
713+
int rc = 0;
718714

719715
/* Node is supposed to be below /firmware */
720716
fw_np = of_find_node_by_name(NULL, "firmware");
@@ -733,6 +729,14 @@ static int __init optee_driver_init(void)
733729
if (IS_ERR(optee))
734730
return PTR_ERR(optee);
735731

732+
rc = optee_enumerate_devices();
733+
if (rc) {
734+
optee_remove(optee);
735+
return rc;
736+
}
737+
738+
pr_info("initialized driver\n");
739+
736740
optee_svc = optee;
737741

738742
optee_bm_enable();

0 commit comments

Comments
 (0)