[PATCH 2/2] drm/radeon: fix userptr BO unpin bug

Christian König deathsimple at vodafone.de
Fri May 1 03:34:13 PDT 2015


From: "monk.liu" <monk.liu at amd.com>

Fixing a memory leak with userptrs.

Signed-off-by: monk.liu <monk.liu at amd.com>
Signed-off-by: Christian König <christian.koenig at amd.com>
CC: stable at vger.kernel.org
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index b292aca..e661841 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -606,13 +606,18 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
 	dma_unmap_sg(rdev->dev, ttm->sg->sgl, ttm->sg->nents, direction);
 
 	for_each_sg(ttm->sg->sgl, sg, ttm->sg->nents, i) {
+		int len = sg->length >> PAGE_SHIFT;
 		struct page *page = sg_page(sg);
+		while (len > 0) {
+			if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
+				set_page_dirty(page);
 
-		if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
-			set_page_dirty(page);
+			mark_page_accessed(page);
+			page_cache_release(page);
 
-		mark_page_accessed(page);
-		page_cache_release(page);
+			page++;
+			len--;
+		}
 	}
 
 	sg_free_table(ttm->sg);
-- 
1.9.1



More information about the dri-devel mailing list