optee: add optee_pool_op_free_helper()
authorJens Wiklander <jens.wiklander@linaro.org>
Fri, 4 Feb 2022 09:33:55 +0000 (10:33 +0100)
committerJens Wiklander <jens.wiklander@linaro.org>
Wed, 16 Feb 2022 06:49:41 +0000 (07:49 +0100)
Adds a common helper function to free a tee_shm allocated using the
helper function optee_pool_op_alloc_helper().

Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
drivers/tee/optee/core.c
drivers/tee/optee/ffa_abi.c
drivers/tee/optee/optee_private.h
drivers/tee/optee/smc_abi.c

index f4bccb5f0e93b1be648d715f5d792fb017cd33e4..daf947e98d141209b13a4d6b1af1f82f708fe377 100644 (file)
@@ -69,6 +69,16 @@ err:
        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));
index fb7345941024d2eb3090e00aa51ed76ee380d013..8cd9c70a9268663edaecce921b60808f1c5978d1 100644 (file)
@@ -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)
index df3a483bbf46e1c4884ca40790f244afad23b9e7..e77765c7887830098304059dc597fc9758ba93c4 100644 (file)
@@ -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);
index 7580d52b38520489d1337688f9263ac5af04ea3d..ef3e27b602e6be51049b91e7a3a6efe456887353 100644 (file)
@@ -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)