public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: fix 32-bit compiler warning
@ 2015-10-07  7:41 Arnd Bergmann
  2015-10-07  8:57 ` Christian König
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2015-10-07  7:41 UTC (permalink / raw)
  To: linux-arm-kernel

The new amdgpu driver passes a user space pointer in a 64-bit structure
member, which is the correct way to do it, but it attempts to
directly cast it to a __user pointer in the kernel, which causes
a warning in three places:

drm/amd/amdgpu/amdgpu_cs.c: In function 'amdgpu_cs_parser_init':
drm/amd/amdgpu/amdgpu_cs.c:180:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  chunk_array_user = (uint64_t __user *)(cs->in.chunks);

This changes all three to add an intermediate cast to 'unsigned long'
as other drivers do. This avoids the warning and works correctly on
both 32-bit and 64-bit architectures.

Signed-off-by: Arnd Bergmann <arnd@arndb•de>

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index cb3c274edb0a..fd16652aa277 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -177,7 +177,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
 
 	/* get chunks */
 	INIT_LIST_HEAD(&p->validated);
-	chunk_array_user = (uint64_t __user *)(cs->in.chunks);
+	chunk_array_user = (uint64_t __user *)(unsigned long)(cs->in.chunks);
 	if (copy_from_user(chunk_array, chunk_array_user,
 			   sizeof(uint64_t)*cs->in.num_chunks)) {
 		ret = -EFAULT;
@@ -197,7 +197,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
 		struct drm_amdgpu_cs_chunk user_chunk;
 		uint32_t __user *cdata;
 
-		chunk_ptr = (void __user *)chunk_array[i];
+		chunk_ptr = (void __user *)(unsigned long)chunk_array[i];
 		if (copy_from_user(&user_chunk, chunk_ptr,
 				       sizeof(struct drm_amdgpu_cs_chunk))) {
 			ret = -EFAULT;
@@ -208,7 +208,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
 		p->chunks[i].length_dw = user_chunk.length_dw;
 
 		size = p->chunks[i].length_dw;
-		cdata = (void __user *)user_chunk.chunk_data;
+		cdata = (void __user *)(unsigned long)user_chunk.chunk_data;
 		p->chunks[i].user_ptr = cdata;
 
 		p->chunks[i].kdata = drm_malloc_ab(size, sizeof(uint32_t));

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] drm/amdgpu: fix 32-bit compiler warning
  2015-10-07  7:41 [PATCH] drm/amdgpu: fix 32-bit compiler warning Arnd Bergmann
@ 2015-10-07  8:57 ` Christian König
  2015-10-07  9:18   ` Arnd Bergmann
  2015-10-07  9:21   ` Chris Wilson
  0 siblings, 2 replies; 5+ messages in thread
From: Christian König @ 2015-10-07  8:57 UTC (permalink / raw)
  To: linux-arm-kernel

On 07.10.2015 09:41, Arnd Bergmann wrote:
> The new amdgpu driver passes a user space pointer in a 64-bit structure
> member, which is the correct way to do it, but it attempts to
> directly cast it to a __user pointer in the kernel, which causes
> a warning in three places:
>
> drm/amd/amdgpu/amdgpu_cs.c: In function 'amdgpu_cs_parser_init':
> drm/amd/amdgpu/amdgpu_cs.c:180:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>    chunk_array_user = (uint64_t __user *)(cs->in.chunks);
>
> This changes all three to add an intermediate cast to 'unsigned long'
> as other drivers do. This avoids the warning and works correctly on
> both 32-bit and 64-bit architectures.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb•de>

Well if I'm not completely mistaken this is the second time we need to 
fix this because somebody thought the cast was unnecessary.

Anyway the patch is Reviewed-by: Christian K?nig 
<christian.koenig@amd•com> and I'm going to keep an eye open for the 
next time somebody tries to remove this.

Regards,
Christian.

>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index cb3c274edb0a..fd16652aa277 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -177,7 +177,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
>   
>   	/* get chunks */
>   	INIT_LIST_HEAD(&p->validated);
> -	chunk_array_user = (uint64_t __user *)(cs->in.chunks);
> +	chunk_array_user = (uint64_t __user *)(unsigned long)(cs->in.chunks);
>   	if (copy_from_user(chunk_array, chunk_array_user,
>   			   sizeof(uint64_t)*cs->in.num_chunks)) {
>   		ret = -EFAULT;
> @@ -197,7 +197,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
>   		struct drm_amdgpu_cs_chunk user_chunk;
>   		uint32_t __user *cdata;
>   
> -		chunk_ptr = (void __user *)chunk_array[i];
> +		chunk_ptr = (void __user *)(unsigned long)chunk_array[i];
>   		if (copy_from_user(&user_chunk, chunk_ptr,
>   				       sizeof(struct drm_amdgpu_cs_chunk))) {
>   			ret = -EFAULT;
> @@ -208,7 +208,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
>   		p->chunks[i].length_dw = user_chunk.length_dw;
>   
>   		size = p->chunks[i].length_dw;
> -		cdata = (void __user *)user_chunk.chunk_data;
> +		cdata = (void __user *)(unsigned long)user_chunk.chunk_data;
>   		p->chunks[i].user_ptr = cdata;
>   
>   		p->chunks[i].kdata = drm_malloc_ab(size, sizeof(uint32_t));
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] drm/amdgpu: fix 32-bit compiler warning
  2015-10-07  8:57 ` Christian König
@ 2015-10-07  9:18   ` Arnd Bergmann
  2015-10-07 14:00     ` Alex Deucher
  2015-10-07  9:21   ` Chris Wilson
  1 sibling, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2015-10-07  9:18 UTC (permalink / raw)
  To: linux-arm-kernel

On Wednesday 07 October 2015 10:57:11 Christian K?nig wrote:
> On 07.10.2015 09:41, Arnd Bergmann wrote:
> > The new amdgpu driver passes a user space pointer in a 64-bit structure
> > member, which is the correct way to do it, but it attempts to
> > directly cast it to a __user pointer in the kernel, which causes
> > a warning in three places:
> >
> > drm/amd/amdgpu/amdgpu_cs.c: In function 'amdgpu_cs_parser_init':
> > drm/amd/amdgpu/amdgpu_cs.c:180:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> >    chunk_array_user = (uint64_t __user *)(cs->in.chunks);
> >
> > This changes all three to add an intermediate cast to 'unsigned long'
> > as other drivers do. This avoids the warning and works correctly on
> > both 32-bit and 64-bit architectures.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb•de>
> 
> Well if I'm not completely mistaken this is the second time we need to 
> fix this because somebody thought the cast was unnecessary.
> 
> Anyway the patch is Reviewed-by: Christian K?nig 
> <christian.koenig@amd•com> and I'm going to keep an eye open for the 
> next time somebody tries to remove this.
> 

Ok, thanks.

I guess I should have added

Fixes: e60b344f6c0eff ("drm/amdgpu: optimize amdgpu_parser_init")

	Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] drm/amdgpu: fix 32-bit compiler warning
  2015-10-07  8:57 ` Christian König
  2015-10-07  9:18   ` Arnd Bergmann
@ 2015-10-07  9:21   ` Chris Wilson
  1 sibling, 0 replies; 5+ messages in thread
From: Chris Wilson @ 2015-10-07  9:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Oct 07, 2015 at 10:57:11AM +0200, Christian K?nig wrote:
> On 07.10.2015 09:41, Arnd Bergmann wrote:
> >The new amdgpu driver passes a user space pointer in a 64-bit structure
> >member, which is the correct way to do it, but it attempts to
> >directly cast it to a __user pointer in the kernel, which causes
> >a warning in three places:
> >
> >drm/amd/amdgpu/amdgpu_cs.c: In function 'amdgpu_cs_parser_init':
> >drm/amd/amdgpu/amdgpu_cs.c:180:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> >   chunk_array_user = (uint64_t __user *)(cs->in.chunks);
> >
> >This changes all three to add an intermediate cast to 'unsigned long'
> >as other drivers do. This avoids the warning and works correctly on
> >both 32-bit and 64-bit architectures.
> >
> >Signed-off-by: Arnd Bergmann <arnd@arndb•de>
> 
> Well if I'm not completely mistaken this is the second time we need
> to fix this because somebody thought the cast was unnecessary.
> 
> Anyway the patch is Reviewed-by: Christian K?nig
> <christian.koenig@amd•com> and I'm going to keep an eye open for the
> next time somebody tries to remove this.

We use

static inline void __user *to_user_ptr(u64 address)
{
        return (void __user *)(uintptr_t)address;
}

to make the intention clear and hide the cast from prying eyes.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] drm/amdgpu: fix 32-bit compiler warning
  2015-10-07  9:18   ` Arnd Bergmann
@ 2015-10-07 14:00     ` Alex Deucher
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Deucher @ 2015-10-07 14:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Oct 7, 2015 at 5:18 AM, Arnd Bergmann <arnd@arndb•de> wrote:
> On Wednesday 07 October 2015 10:57:11 Christian K?nig wrote:
>> On 07.10.2015 09:41, Arnd Bergmann wrote:
>> > The new amdgpu driver passes a user space pointer in a 64-bit structure
>> > member, which is the correct way to do it, but it attempts to
>> > directly cast it to a __user pointer in the kernel, which causes
>> > a warning in three places:
>> >
>> > drm/amd/amdgpu/amdgpu_cs.c: In function 'amdgpu_cs_parser_init':
>> > drm/amd/amdgpu/amdgpu_cs.c:180:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>> >    chunk_array_user = (uint64_t __user *)(cs->in.chunks);
>> >
>> > This changes all three to add an intermediate cast to 'unsigned long'
>> > as other drivers do. This avoids the warning and works correctly on
>> > both 32-bit and 64-bit architectures.
>> >
>> > Signed-off-by: Arnd Bergmann <arnd@arndb•de>
>>
>> Well if I'm not completely mistaken this is the second time we need to
>> fix this because somebody thought the cast was unnecessary.
>>
>> Anyway the patch is Reviewed-by: Christian K?nig
>> <christian.koenig@amd•com> and I'm going to keep an eye open for the
>> next time somebody tries to remove this.
>>
>
> Ok, thanks.
>
> I guess I should have added
>
> Fixes: e60b344f6c0eff ("drm/amdgpu: optimize amdgpu_parser_init")

Applied this that comment added.

Thanks!

Alex

>
>         Arnd
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-10-07 14:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-07  7:41 [PATCH] drm/amdgpu: fix 32-bit compiler warning Arnd Bergmann
2015-10-07  8:57 ` Christian König
2015-10-07  9:18   ` Arnd Bergmann
2015-10-07 14:00     ` Alex Deucher
2015-10-07  9:21   ` Chris Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox