[Intel-gfx] [PATCH i-g-t 3/7] Remove gem_mmap__{cpu, gtt, wc} return value MAP_FAILED asserts

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Fri Oct 9 09:19:12 PDT 2015


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

gem_mmap__{cpu,gtt,wc} never return MAP_FAILED, it gets converted to
NULL internally. So don't go asserting that the returned value is
not MAP_FAILED.

Done with coccinelle:
@@
type T;
identifier I;
@@
(
 I = gem_mmap__gtt(...);
|
 I = gem_mmap__cpu(...);
|
 I = gem_mmap__wc(...);
)
 ...
(
- igt_assert(I != MAP_FAILED);
+ igt_assert(I);
|
- igt_assert(I && I != MAP_FAILED);
+ igt_assert(I);
|
- igt_assert(I != (T *) MAP_FAILED);
+ igt_assert(I);
|
- igt_assert(I != NULL);
+ igt_assert(I);
)

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 tests/drv_suspend.c        |  6 +++---
 tests/gem_concurrent_all.c | 12 ++++++------
 tests/gem_madvise.c        |  2 +-
 tests/gem_mmap_gtt.c       | 12 ++++++------
 tests/gem_mmap_wc.c        | 14 +++++++-------
 tests/gem_userptr_blits.c  |  2 +-
 6 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/tests/drv_suspend.c b/tests/drv_suspend.c
index 4014241..4e84d1c 100644
--- a/tests/drv_suspend.c
+++ b/tests/drv_suspend.c
@@ -57,19 +57,19 @@ test_fence_restore(int fd, bool tiled2untiled, bool hibernate)
 
 	/* Access the buffer objects in the order we want to have the laid out. */
 	ptr1 = gem_mmap__gtt(fd, handle1, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr1 != MAP_FAILED);
+	igt_assert(ptr1);
 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
 		ptr1[i] = i;
 
 	ptr_tiled = gem_mmap__gtt(fd, handle_tiled, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr_tiled != MAP_FAILED);
+	igt_assert(ptr_tiled);
 	if (tiled2untiled)
 		gem_set_tiling(fd, handle_tiled, I915_TILING_X, 2048);
 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
 		ptr_tiled[i] = i;
 
 	ptr2 = gem_mmap__gtt(fd, handle2, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr2 != MAP_FAILED);
+	igt_assert(ptr2);
 	for (i = 0; i < OBJECT_SIZE/sizeof(uint32_t); i++)
 		ptr2[i] = i;
 
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 167f383..6efb977 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -472,9 +472,9 @@ static void cpu_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
 	gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_CPU, 0);
 	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
 	s = gem_mmap__cpu(fd, src->handle, 0, size, PROT_READ);
-	igt_assert(s != NULL);
+	igt_assert(s);
 	d = gem_mmap__cpu(fd, dst->handle, 0, size, PROT_WRITE);
-	igt_assert(d != NULL);
+	igt_assert(d);
 
 	memcpy(d, s, size);
 
@@ -491,9 +491,9 @@ static void gtt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
 	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
 
 	s = gem_mmap__gtt(fd, src->handle, size, PROT_READ);
-	igt_assert(s != NULL);
+	igt_assert(s);
 	d = gem_mmap__gtt(fd, dst->handle, size, PROT_WRITE);
-	igt_assert(d != NULL);
+	igt_assert(d);
 
 	memcpy(d, s, size);
 
@@ -510,9 +510,9 @@ static void wc_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
 	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
 
 	s = gem_mmap__wc(fd, src->handle, 0, size, PROT_READ);
-	igt_assert(s != NULL);
+	igt_assert(s);
 	d = gem_mmap__wc(fd, dst->handle, 0, size, PROT_WRITE);
-	igt_assert(d != NULL);
+	igt_assert(d);
 
 	memcpy(d, s, size);
 
diff --git a/tests/gem_madvise.c b/tests/gem_madvise.c
index 359f490..d0f378e 100644
--- a/tests/gem_madvise.c
+++ b/tests/gem_madvise.c
@@ -78,7 +78,7 @@ dontneed_after_mmap(void)
 
 	handle = gem_create(fd, OBJECT_SIZE);
 	ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr != NULL);
+	igt_assert(ptr);
 	gem_madvise(fd, handle, I915_MADV_DONTNEED);
 	close(fd);
 
diff --git a/tests/gem_mmap_gtt.c b/tests/gem_mmap_gtt.c
index 1624a6b..5b782c9 100644
--- a/tests/gem_mmap_gtt.c
+++ b/tests/gem_mmap_gtt.c
@@ -57,7 +57,7 @@ mmap_bo(int fd, uint32_t handle)
 	void *ptr;
 
 	ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr != MAP_FAILED);
+	igt_assert(ptr);
 
 	return ptr;
 }
@@ -180,7 +180,7 @@ test_read_write(int fd, enum test_read_write order)
 	handle = gem_create(fd, OBJECT_SIZE);
 
 	ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr != MAP_FAILED);
+	igt_assert(ptr);
 
 	if (order == READ_BEFORE_WRITE) {
 		val = *(uint32_t *)ptr;
@@ -204,10 +204,10 @@ test_read_write2(int fd, enum test_read_write order)
 	handle = gem_create(fd, OBJECT_SIZE);
 
 	r = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ);
-	igt_assert(r != MAP_FAILED);
+	igt_assert(r);
 
 	w = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(w != MAP_FAILED);
+	igt_assert(w);
 
 	if (order == READ_BEFORE_WRITE) {
 		val = *(uint32_t *)r;
@@ -441,10 +441,10 @@ test_write_cpu_read_gtt(int fd)
 	handle = gem_create(fd, OBJECT_SIZE);
 
 	dst = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ);
-	igt_assert(dst != (uint32_t *)MAP_FAILED);
+	igt_assert(dst);
 
 	src = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_WRITE);
-	igt_assert(src != (uint32_t *)MAP_FAILED);
+	igt_assert(src);
 
 	gem_close(fd, handle);
 
diff --git a/tests/gem_mmap_wc.c b/tests/gem_mmap_wc.c
index e312805..11463ca 100644
--- a/tests/gem_mmap_wc.c
+++ b/tests/gem_mmap_wc.c
@@ -63,7 +63,7 @@ mmap_bo(int fd, uint32_t handle)
 	void *ptr;
 
 	ptr = gem_mmap__wc(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr && ptr != MAP_FAILED);
+	igt_assert(ptr);
 
 	return ptr;
 }
@@ -184,10 +184,10 @@ test_read_write2(int fd, enum test_read_write order)
 	set_domain(fd, handle);
 
 	r = gem_mmap__wc(fd, handle, 0, OBJECT_SIZE, PROT_READ);
-	igt_assert(r != MAP_FAILED);
+	igt_assert(r);
 
 	w = gem_mmap__wc(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(w != MAP_FAILED);
+	igt_assert(w);
 
 	if (order == READ_BEFORE_WRITE) {
 		val = *(uint32_t *)r;
@@ -289,10 +289,10 @@ test_write_cpu_read_wc(int fd, int force_domain)
 	handle = gem_create(fd, OBJECT_SIZE);
 
 	dst = gem_mmap__wc(fd, handle, 0, OBJECT_SIZE, PROT_READ);
-	igt_assert(dst != (uint32_t *)MAP_FAILED);
+	igt_assert(dst);
 
 	src = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_WRITE);
-	igt_assert(src != (uint32_t *)MAP_FAILED);
+	igt_assert(src);
 
 	memset(src, 0xaa, OBJECT_SIZE);
 	if (force_domain)
@@ -316,10 +316,10 @@ test_write_gtt_read_wc(int fd)
 	set_domain(fd, handle);
 
 	dst = gem_mmap__wc(fd, handle, 0, OBJECT_SIZE, PROT_READ);
-	igt_assert(dst != (uint32_t *)MAP_FAILED);
+	igt_assert(dst);
 
 	src = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_WRITE);
-	igt_assert(src != (uint32_t *)MAP_FAILED);
+	igt_assert(src);
 
 	memset(src, 0xaa, OBJECT_SIZE);
 	igt_assert(memcmp(dst, src, OBJECT_SIZE) == 0);
diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c
index d161b6c..6fff3a9 100644
--- a/tests/gem_userptr_blits.c
+++ b/tests/gem_userptr_blits.c
@@ -546,7 +546,7 @@ static int test_invalid_gtt_mapping(int fd)
 	handle = create_bo(fd, 0);
 	ptr = gem_mmap__gtt(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE);
 	gem_close(fd, handle);
-	igt_assert(ptr != NULL);
+	igt_assert(ptr);
 	igt_assert(((unsigned long)ptr & (PAGE_SIZE - 1)) == 0);
 	igt_assert((sizeof(linear) & (PAGE_SIZE - 1)) == 0);
 
-- 
2.4.9



More information about the Intel-gfx mailing list