Skip to contentSkip to conversation

optee: Fix multi page dynamic shm pool alloc

PATCH New Sumit Garg 1 participant 1 message Dec 30, 2019

Subsystems (2)
lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

PATCH v2 1/1 optee: Fix multi page dynamic shm pool alloc

optee_shm_register() expected pages to be passed as an array of page pointers rather than as an array of contiguous pages. So fix that via correctly passing pages as per expectation.

Fixes a249dd200d03 ("tee: optee: Fix dynamic shm pool allocations")

---

Changes in v2:
- Fix memory leak for "pages" pointer.

 drivers/tee/optee/shm_pool.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/tee/optee/shm_pool.c +14 -1
index 0332a53..d767eeb 100644
@@ -28,9 +28,22 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
 	shm->size = PAGE_SIZE << order;
 
 	if (shm->flags & TEE_SHM_DMA_BUF) {
+		unsigned int nr_pages = 1 << order, i;
+		struct page **pages;
+
+		pages = kcalloc(nr_pages, sizeof(pages), GFP_KERNEL);
+		if (!pages)
+			return -ENOMEM;
+
+		for (i = 0; i < nr_pages; i++) {
+			pages[i] = page;
+			page++;
+		}
+
 		shm->flags |= TEE_SHM_REGISTER;
-		rc = optee_shm_register(shm->ctx, shm, &page, 1 << order,
+		rc = optee_shm_register(shm->ctx, shm, pages, nr_pages,
 					(unsigned long)shm->kaddr);
+		kfree(pages);
 	}
 
 	return rc;
Signature · 1 line
2.7.4