diff mbox

[3/3] drm/gma500: Fix mem leak of cursor objects on Cedarview

Message ID 1369046822-3657-4-git-send-email-patrik.r.jakobsson@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Patrik Jakobsson May 20, 2013, 10:47 a.m. UTC
All dumb allocated buffers are now automatically pinned so no extra
pinning is needed. Also properly unreference gem objects so they can be
freed up properly. This only affects Cedarview chips.

Signed-off-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
---
 drivers/gpu/drm/gma500/cdv_intel_display.c | 39 ++++++++----------------------
 1 file changed, 10 insertions(+), 29 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/gma500/cdv_intel_display.c b/drivers/gpu/drm/gma500/cdv_intel_display.c
index 3cfd093..a85b9a1 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_display.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_display.c
@@ -1462,7 +1462,7 @@  static int cdv_intel_crtc_cursor_set(struct drm_crtc *crtc,
 	size_t addr = 0;
 	struct gtt_range *gt;
 	struct drm_gem_object *obj;
-	int ret;
+	int ret = 0;
 
 	/* if we want to turn of the cursor ignore width and height */
 	if (!handle) {
@@ -1475,15 +1475,7 @@  static int cdv_intel_crtc_cursor_set(struct drm_crtc *crtc,
 			gma_power_end(dev);
 		}
 
-		/* unpin the old GEM object */
-		if (psb_intel_crtc->cursor_obj) {
-			gt = container_of(psb_intel_crtc->cursor_obj,
-							struct gtt_range, gem);
-			psb_gtt_unpin(gt);
-			drm_gem_object_unreference(psb_intel_crtc->cursor_obj);
-			psb_intel_crtc->cursor_obj = NULL;
-		}
-
+		psb_intel_crtc->cursor_obj = NULL;
 		return 0;
 	}
 
@@ -1499,20 +1491,13 @@  static int cdv_intel_crtc_cursor_set(struct drm_crtc *crtc,
 
 	if (obj->size < width * height * 4) {
 		dev_dbg(dev->dev, "buffer is to small\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto unref_cursor;
 	}
 
 	gt = container_of(obj, struct gtt_range, gem);
-
-	/* Pin the memory into the GTT */
-	ret = psb_gtt_pin(gt);
-	if (ret) {
-		dev_err(dev->dev, "Can not pin down handle 0x%x\n", handle);
-		return ret;
-	}
-
+	WARN_ON(gt->in_gart < 1);
 	addr = gt->offset;	/* Or resource.start ??? */
-
 	psb_intel_crtc->cursor_addr = addr;
 
 	temp = 0;
@@ -1526,15 +1511,11 @@  static int cdv_intel_crtc_cursor_set(struct drm_crtc *crtc,
 		gma_power_end(dev);
 	}
 
-	/* unpin the old GEM object */
-	if (psb_intel_crtc->cursor_obj) {
-		gt = container_of(psb_intel_crtc->cursor_obj,
-							struct gtt_range, gem);
-		psb_gtt_unpin(gt);
-		drm_gem_object_unreference(psb_intel_crtc->cursor_obj);
-		psb_intel_crtc->cursor_obj = obj;
-	}
-	return 0;
+	psb_intel_crtc->cursor_obj = obj;
+
+unref_cursor:
+	drm_gem_object_unreference(psb_intel_crtc->cursor_obj);
+	return ret;
 }
 
 static int cdv_intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)