Skip to content

Commit b30a9b0

Browse files
jenswi-linarogregkh
authored andcommitted
tee: optee: fix device enumeration error handling
[ Upstream commit 03212e3 ] 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 <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5c179c0 commit b30a9b0

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

drivers/tee/optee/core.c

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

646-
rc = optee_enumerate_devices();
647-
if (rc)
648-
goto err;
649-
650-
pr_info("initialized driver\n");
651646
return optee;
652647
err:
653648
if (optee) {
@@ -702,9 +697,10 @@ static struct optee *optee_svc;
702697

703698
static int __init optee_driver_init(void)
704699
{
705-
struct device_node *fw_np;
706-
struct device_node *np;
707-
struct optee *optee;
700+
struct device_node *fw_np = NULL;
701+
struct device_node *np = NULL;
702+
struct optee *optee = NULL;
703+
int rc = 0;
708704

709705
/* Node is supposed to be below /firmware */
710706
fw_np = of_find_node_by_name(NULL, "firmware");
@@ -723,6 +719,14 @@ static int __init optee_driver_init(void)
723719
if (IS_ERR(optee))
724720
return PTR_ERR(optee);
725721

722+
rc = optee_enumerate_devices();
723+
if (rc) {
724+
optee_remove(optee);
725+
return rc;
726+
}
727+
728+
pr_info("initialized driver\n");
729+
726730
optee_svc = optee;
727731

728732
return 0;

0 commit comments

Comments
 (0)