Skip to content

Commit

Permalink
tee: optee: fix device enumeration error handling
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jenswi-linaro authored and jforissier committed Nov 15, 2019
1 parent a37a13f commit 65fa3a3
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions drivers/tee/optee/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,6 @@ static struct optee *optee_probe(struct device_node *np)
if (optee->sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM)
pr_info("dynamic shared memory is enabled\n");

rc = optee_enumerate_devices();
if (rc)
goto err;

pr_info("initialized driver\n");
return optee;
err:
if (optee) {
Expand Down Expand Up @@ -712,9 +707,10 @@ static struct optee *optee_svc;

static int __init optee_driver_init(void)
{
struct device_node *fw_np;
struct device_node *np;
struct optee *optee;
struct device_node *fw_np = NULL;
struct device_node *np = NULL;
struct optee *optee = NULL;
int rc = 0;

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

rc = optee_enumerate_devices();
if (rc) {
optee_remove(optee);
return rc;
}

pr_info("initialized driver\n");

optee_svc = optee;

optee_bm_enable();
Expand Down

0 comments on commit 65fa3a3

Please sign in to comment.