[Nouveau] [PATCH] nouveau: when nouveau_bo_map fails you expect it to not be mapped

Maarten Maathuis madman2003 at gmail.com
Thu Dec 24 10:33:46 PST 2009


- This includes unmapping on failure to sync for cpu access.
- Double mapping will also be punished, so that people fix their code.
---
 nouveau/nouveau_bo.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/nouveau/nouveau_bo.c b/nouveau/nouveau_bo.c
index 10cc8a6..9a7c368 100644
--- a/nouveau/nouveau_bo.c
+++ b/nouveau/nouveau_bo.c
@@ -415,22 +415,28 @@ nouveau_bo_map_range(struct nouveau_bo *bo, uint32_t delta, uint32_t size,
 		     uint32_t flags)
 {
 	struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
-	int ret;
+	int ret = 0;
 
-	if (!nvbo || bo->map)
+	if (!nvbo)
 		return -EINVAL;
 
+	/* People should not double map, let's make sure they will notice. */
+	if (bo->map) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 	if (!nouveau_bo_allocated(nvbo)) {
 		if (nvbo->flags & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)) {
 			ret = nouveau_bo_kalloc(nvbo, NULL);
 			if (ret)
-				return ret;
+				goto out;
 		}
 
 		if (!nouveau_bo_allocated(nvbo)) {
 			ret = nouveau_bo_ualloc(nvbo);
 			if (ret)
-				return ret;
+				goto out;
 		}
 	}
 
@@ -439,19 +445,22 @@ nouveau_bo_map_range(struct nouveau_bo *bo, uint32_t delta, uint32_t size,
 	} else {
 		ret = nouveau_bo_kmap(nvbo);
 		if (ret)
-			return ret;
+			goto out;
 
 		if (!(flags & NOUVEAU_BO_NOSYNC)) {
 			ret = nouveau_bo_wait(bo, (flags & NOUVEAU_BO_WR),
 					      (flags & NOUVEAU_BO_NOWAIT), 0);
 			if (ret)
-				return ret;
+				goto out;
 		}
 
 		bo->map = (char *)nvbo->map + delta;
 	}
 
-	return 0;
+out:
+	if (ret)
+		nouveau_bo_unmap(bo);
+	return ret;
 }
 
 void
-- 
1.6.6.rc4



More information about the Nouveau mailing list