Skip to content

Commit ec185dd

Browse files
tyhicksjenswi-linaro
authored andcommitted
optee: Fix memory leak when failing to register shm pages
Free the previously allocated pages when we encounter an error condition while attempting to register the pages with the secure world. Fixes: a249dd2 ("tee: optee: Fix dynamic shm pool allocations") Fixes: 5a769f6 ("optee: Fix multi page dynamic shm pool alloc") Cc: [email protected] Signed-off-by: Tyler Hicks <[email protected]> Reviewed-by: Jens Wiklander <[email protected]> Reviewed-by: Sumit Garg <[email protected]> Signed-off-by: Jens Wiklander <[email protected]>
1 parent 2734d6c commit ec185dd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/tee/optee/shm_pool.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
3232
struct page **pages;
3333

3434
pages = kcalloc(nr_pages, sizeof(pages), GFP_KERNEL);
35-
if (!pages)
36-
return -ENOMEM;
35+
if (!pages) {
36+
rc = -ENOMEM;
37+
goto err;
38+
}
3739

3840
for (i = 0; i < nr_pages; i++) {
3941
pages[i] = page;
@@ -44,8 +46,14 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
4446
rc = optee_shm_register(shm->ctx, shm, pages, nr_pages,
4547
(unsigned long)shm->kaddr);
4648
kfree(pages);
49+
if (rc)
50+
goto err;
4751
}
4852

53+
return 0;
54+
55+
err:
56+
__free_pages(page, order);
4957
return rc;
5058
}
5159

0 commit comments

Comments
 (0)