Skip to content

Commit

Permalink
optee: add optee_pool_op_free_helper()
Browse files Browse the repository at this point in the history
Adds a common helper function to free a tee_shm allocated using the
helper function optee_pool_op_alloc_helper().

Reviewed-by: Sumit Garg <[email protected]>
Signed-off-by: Jens Wiklander <[email protected]>
  • Loading branch information
jenswi-linaro committed Feb 16, 2022
1 parent 5d41f1b commit 924e322
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
10 changes: 10 additions & 0 deletions drivers/tee/optee/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
return rc;
}

void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
int (*shm_unregister)(struct tee_context *ctx,
struct tee_shm *shm))
{
if (shm_unregister)
shm_unregister(shm->ctx, shm);
free_pages((unsigned long)shm->kaddr, get_order(shm->size));
shm->kaddr = NULL;
}

static void optee_bus_scan(struct work_struct *work)
{
WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP));
Expand Down
4 changes: 1 addition & 3 deletions drivers/tee/optee/ffa_abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@ static int pool_ffa_op_alloc(struct tee_shm_pool *pool,
static void pool_ffa_op_free(struct tee_shm_pool *pool,
struct tee_shm *shm)
{
optee_ffa_shm_unregister(shm->ctx, shm);
free_pages((unsigned long)shm->kaddr, get_order(shm->size));
shm->kaddr = NULL;
optee_pool_op_free_helper(pool, shm, optee_ffa_shm_unregister);
}

static void pool_ffa_op_destroy_pool(struct tee_shm_pool *pool)
Expand Down
3 changes: 3 additions & 0 deletions drivers/tee/optee/optee_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
struct page **pages,
size_t num_pages,
unsigned long start));
void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
int (*shm_unregister)(struct tee_context *ctx,
struct tee_shm *shm));


void optee_remove_common(struct optee *optee);
Expand Down
7 changes: 3 additions & 4 deletions drivers/tee/optee/smc_abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,9 @@ static void pool_op_free(struct tee_shm_pool *pool,
struct tee_shm *shm)
{
if (!(shm->flags & TEE_SHM_PRIV))
optee_shm_unregister(shm->ctx, shm);

free_pages((unsigned long)shm->kaddr, get_order(shm->size));
shm->kaddr = NULL;
optee_pool_op_free_helper(pool, shm, optee_shm_unregister);
else
optee_pool_op_free_helper(pool, shm, NULL);
}

static void pool_op_destroy_pool(struct tee_shm_pool *pool)
Expand Down

0 comments on commit 924e322

Please sign in to comment.