Adds a common helper function to free a tee_shm allocated using the helper function optee_pool_op_alloc_helper().
Unified · Split
| @@ -69,6 +69,16 @@ err: · 68 unmodified lines | |||
| 69 | return rc; | 69 | return rc; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm, | ||
| 73 | int (*shm_unregister)(struct tee_context *ctx, | ||
| 74 | struct tee_shm *shm)) | ||
| 75 | { | ||
| 76 | if (shm_unregister) | ||
| 77 | shm_unregister(shm->ctx, shm); | ||
| 78 | free_pages((unsigned long)shm->kaddr, get_order(shm->size)); | ||
| 79 | shm->kaddr = NULL; | ||
| 80 | } | ||
| 81 | |||
| 72 | static void optee_bus_scan(struct work_struct *work) | 82 | static void optee_bus_scan(struct work_struct *work) |
| 73 | { | 83 | { |
| 74 | WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP)); | 84 | WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP)); |
| @@ -379,9 +379,7 @@ static int pool_ffa_op_alloc(struct tee_shm_pool *pool, · 378 unmodified lines | |||
| 379 | static void pool_ffa_op_free(struct tee_shm_pool *pool, | 379 | static void pool_ffa_op_free(struct tee_shm_pool *pool, |
| 380 | struct tee_shm *shm) | 380 | struct tee_shm *shm) |
| 381 | { | 381 | { |
| 382 | optee_ffa_shm_unregister(shm->ctx, shm); | 382 | optee_pool_op_free_helper(pool, shm, optee_ffa_shm_unregister); |
| 383 | free_pages((unsigned long)shm->kaddr, get_order(shm->size)); | ||
| 384 | shm->kaddr = NULL; | ||
| 385 | } | 383 | } |
| 386 | 384 | ||
| 387 | static void pool_ffa_op_destroy_pool(struct tee_shm_pool *pool) | 385 | static void pool_ffa_op_destroy_pool(struct tee_shm_pool *pool) |
| @@ -236,6 +236,9 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm, · 235 unmodified lines | |||
| 236 | struct page **pages, | 236 | struct page **pages, |
| 237 | size_t num_pages, | 237 | size_t num_pages, |
| 238 | unsigned long start)); | 238 | unsigned long start)); |
| 239 | void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm, | ||
| 240 | int (*shm_unregister)(struct tee_context *ctx, | ||
| 241 | struct tee_shm *shm)); | ||
| 239 | 242 | ||
| 240 | 243 | ||
| 241 | void optee_remove_common(struct optee *optee); | 244 | void optee_remove_common(struct optee *optee); |
| @@ -558,10 +558,9 @@ static void pool_op_free(struct tee_shm_pool *pool, · 557 unmodified lines | |||
| 558 | struct tee_shm *shm) | 558 | struct tee_shm *shm) |
| 559 | { | 559 | { |
| 560 | if (!(shm->flags & TEE_SHM_PRIV)) | 560 | if (!(shm->flags & TEE_SHM_PRIV)) |
| 561 | optee_shm_unregister(shm->ctx, shm); | 561 | optee_pool_op_free_helper(pool, shm, optee_shm_unregister); |
| 562 | 562 | else | |
| 563 | free_pages((unsigned long)shm->kaddr, get_order(shm->size)); | 563 | optee_pool_op_free_helper(pool, shm, NULL); |
| 564 | shm->kaddr = NULL; | ||
| 565 | } | 564 | } |
| 566 | 565 | ||
| 567 | static void pool_op_destroy_pool(struct tee_shm_pool *pool) | 566 | static void pool_op_destroy_pool(struct tee_shm_pool *pool) |