diff mbox series

[i-g-t] i915/gem_ctx_sseu: Fix 32-bit build

Message ID 20190213093137.22678-1-guillaume.tucker@collabora.com (mailing list archive)
State New, archived
Headers show
Series [i-g-t] i915/gem_ctx_sseu: Fix 32-bit build | expand

Commit Message

Guillaume Tucker Feb. 13, 2019, 9:31 a.m. UTC
This fixes a compiler warning treated as an error when building for
32-bit architectures since their pointer size does not match the size
of drm_i915_gem_context_param.value which is 64 bits:

  CC       i915/gem_ctx_sseu.o
  i915/gem_ctx_sseu.c: In function ‘test_ggtt_args’:
  i915/gem_ctx_sseu.c:384:9: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
    munmap((void *)arg.value, 4096);

It was found while building for arm with gcc 6.3.0 and I suspect the
same problem would arise for i386 or other 32-bit architectures.  The
uintptr_t type is by definition an unsigned integer of the same length
as a pointer on a given architecture, so this should fix the problem
for all architectures up to 64 bits.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
---
 tests/i915/gem_ctx_sseu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Chris Wilson Feb. 13, 2019, 2:08 p.m. UTC | #1
Quoting Guillaume Tucker (2019-02-13 09:31:37)
> This fixes a compiler warning treated as an error when building for
> 32-bit architectures since their pointer size does not match the size
> of drm_i915_gem_context_param.value which is 64 bits:
> 
>   CC       i915/gem_ctx_sseu.o
>   i915/gem_ctx_sseu.c: In function ‘test_ggtt_args’:
>   i915/gem_ctx_sseu.c:384:9: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
>     munmap((void *)arg.value, 4096);
> 
> It was found while building for arm with gcc 6.3.0 and I suspect the
> same problem would arise for i386 or other 32-bit architectures.  The
> uintptr_t type is by definition an unsigned integer of the same length
> as a pointer on a given architecture, so this should fix the problem
> for all architectures up to 64 bits.
> 
> Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>

At some point, we should save our eyesight and do u64_to_pointer().
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Chris Wilson Feb. 13, 2019, 2:12 p.m. UTC | #2
Quoting Chris Wilson (2019-02-13 14:08:02)
> Quoting Guillaume Tucker (2019-02-13 09:31:37)
> > This fixes a compiler warning treated as an error when building for
> > 32-bit architectures since their pointer size does not match the size
> > of drm_i915_gem_context_param.value which is 64 bits:
> > 
> >   CC       i915/gem_ctx_sseu.o
> >   i915/gem_ctx_sseu.c: In function ‘test_ggtt_args’:
> >   i915/gem_ctx_sseu.c:384:9: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
> >     munmap((void *)arg.value, 4096);
> > 
> > It was found while building for arm with gcc 6.3.0 and I suspect the
> > same problem would arise for i386 or other 32-bit architectures.  The
> > uintptr_t type is by definition an unsigned integer of the same length
> > as a pointer on a given architecture, so this should fix the problem
> > for all architectures up to 64 bits.
> > 
> > Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
> 
> At some point, we should save our eyesight and do u64_to_pointer().
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

And pushed, having forgotten I wasn't using dim and forgot to auto-sob.
-Chris
diff mbox series

Patch

diff --git a/tests/i915/gem_ctx_sseu.c b/tests/i915/gem_ctx_sseu.c
index 16609bee61c8..3afa5c152939 100644
--- a/tests/i915/gem_ctx_sseu.c
+++ b/tests/i915/gem_ctx_sseu.c
@@ -381,7 +381,7 @@  test_ggtt_args(int fd)
 	igt_assert_eq(__gem_context_get_param(fd, &arg), 0);
 	igt_assert_eq(__gem_context_set_param(fd, &arg), 0);
 
-	munmap((void *)arg.value, 4096);
+	munmap((void *)(uintptr_t)arg.value, 4096);
 	gem_close(fd, bo);
 	gem_context_destroy(fd, arg.ctx_id);
 }