gpu: ion: Fix lockdep issue in ion_page_pool

Currently the mutex is held while kmalloc is called, under a low memory
condition this might trigger the shrinker which also takes this mutex.
Refactor so the mutex is not held during allocation.

Change-Id: I3ebbc3e1e618aeb2b974bcc032e89f097eb526d5
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Git-commit: 1fc3f5102601e392d644762e2f79e774c1e225e3
Git-repo: https://android.googlesource.com/kernel/common
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
diff --git a/drivers/gpu/ion/ion_page_pool.c b/drivers/gpu/ion/ion_page_pool.c
index 45b8d7b..da4dc05 100644
--- a/drivers/gpu/ion/ion_page_pool.c
+++ b/drivers/gpu/ion/ion_page_pool.c
@@ -54,6 +54,8 @@
 	item = kmalloc(sizeof(struct ion_page_pool_item), GFP_KERNEL);
 	if (!item)
 		return -ENOMEM;
+
+	mutex_lock(&pool->mutex);
 	item->page = page;
 	if (PageHighMem(page)) {
 		list_add_tail(&item->list, &pool->high_items);
@@ -62,6 +64,7 @@
 		list_add_tail(&item->list, &pool->low_items);
 		pool->low_count++;
 	}
+	mutex_unlock(&pool->mutex);
 	return 0;
 }
 
@@ -111,9 +114,7 @@
 {
 	int ret;
 
-	mutex_lock(&pool->mutex);
 	ret = ion_page_pool_add(pool, page);
-	mutex_unlock(&pool->mutex);
 	if (ret)
 		ion_page_pool_free_pages(pool, page);
 }