Skip to contentSkip to conversation

nouveau: when nouveau_bo_map fails you expect it to not be mapped

PATCH In review Maarten Maathuis 2 participants 3 messages Dec 24, 2009 – Dec 25, 2009 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nouveau: when nouveau_bo_map fails you expect it to not be mapped

- 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(-)
nouveau/nouveau_bo.c +16 -7
index 10cc8a6..9a7c368 100644
@@ -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
Signature · 1 line
1.6.6.rc4

A message that is not in the archive (sent off-list or not yet received): 1261679626-24552-1-git-send-email-madman2003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 2 lines · Maarten Maathuis

- This includes unmapping on failure to sync for cpu access.
- Double mapping will also be punished, so that people fix their code.

Not sure that'll work too well for sw fallbacks, you can same src/dst pixmap or same
texture/colorbuffer and the mapping code should just work.

Dave.

A message that is not in the archive (sent off-list or not yet received): 21d7e9970912250243t72014a51g3d92469bfe1eb3de-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 7 lines · Dave Airlie
Quoted 2 lines · Maarten Maathuis

- This includes unmapping on failure to sync for cpu access.
- Double mapping will also be punished, so that people fix their code.

Not sure that'll work too well for sw fallbacks, you can same src/dst pixmap or same
texture/colorbuffer and the mapping code should just work.

At least exa these days handles this properly (eg no double mapping), i don't know about the gallium drivers.

Quoted 3 lines

Dave.