Re: [PATCH v2 libdrm] amdgpu: Eliminate void* arithmetic in amdgpu_find_bo_by_cpu_mapping

2018-08-16 Thread Zhang, Jerry
 Reviewed-by: Junwei Zhang 

Regards,
Jerry(Junwei Zhang)


From: amd-gfx  on behalf of Michel 
Dänzer 
Sent: Thursday, August 16, 2018 9:54:29 PM
To: amd-gfx@lists.freedesktop.org
Subject: [PATCH v2 libdrm] amdgpu: Eliminate void* arithmetic in 
amdgpu_find_bo_by_cpu_mapping

From: Michel Dänzer 

Arithmetic using void* pointers isn't defined by the C standard, only as
a GCC extension. Avoids compiler warnings:

../../amdgpu/amdgpu_bo.c: In function ‘amdgpu_find_bo_by_cpu_mapping’:
../../amdgpu/amdgpu_bo.c:554:48: warning: pointer of type ‘void *’ used in 
arithmetic [-Wpointer-arith]
   if (cpu >= bo->cpu_ptr && cpu < (bo->cpu_ptr + bo->alloc_size))
^
../../amdgpu/amdgpu_bo.c:561:23: warning: pointer of type ‘void *’ used in 
subtraction [-Wpointer-arith]
   *offset_in_bo = cpu - bo->cpu_ptr;
   ^

v2: Use uintptr_t instead of char*, don't change function signature
(Junwei Zhang)

Fixes: 4d454424e1f2 ("amdgpu: add a function to find bo by cpu mapping
 (v2)")
Signed-off-by: Michel Dänzer 
---
 amdgpu/amdgpu_bo.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 86d1c143..8efd014e 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -551,14 +551,15 @@ int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle 
dev,
bo = handle_table_lookup(>bo_handles, i);
if (!bo || !bo->cpu_ptr || size > bo->alloc_size)
continue;
-   if (cpu >= bo->cpu_ptr && cpu < (bo->cpu_ptr + bo->alloc_size))
+   if (cpu >= bo->cpu_ptr &&
+   cpu < (void*)((uintptr_t)bo->cpu_ptr + bo->alloc_size))
break;
}

if (i < dev->bo_handles.max_key) {
atomic_inc(>refcount);
*buf_handle = bo;
-   *offset_in_bo = cpu - bo->cpu_ptr;
+   *offset_in_bo = (uintptr_t)cpu - (uintptr_t)bo->cpu_ptr;
} else {
*buf_handle = NULL;
*offset_in_bo = 0;
--
2.18.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH v2 libdrm] amdgpu: Eliminate void* arithmetic in amdgpu_find_bo_by_cpu_mapping

2018-08-16 Thread Christian König

Am 16.08.2018 um 15:54 schrieb Michel Dänzer:

From: Michel Dänzer 

Arithmetic using void* pointers isn't defined by the C standard, only as
a GCC extension. Avoids compiler warnings:

../../amdgpu/amdgpu_bo.c: In function ‘amdgpu_find_bo_by_cpu_mapping’:
../../amdgpu/amdgpu_bo.c:554:48: warning: pointer of type ‘void *’ used in 
arithmetic [-Wpointer-arith]
if (cpu >= bo->cpu_ptr && cpu < (bo->cpu_ptr + bo->alloc_size))
 ^
../../amdgpu/amdgpu_bo.c:561:23: warning: pointer of type ‘void *’ used in 
subtraction [-Wpointer-arith]
*offset_in_bo = cpu - bo->cpu_ptr;
^

v2: Use uintptr_t instead of char*, don't change function signature
 (Junwei Zhang)

Fixes: 4d454424e1f2 ("amdgpu: add a function to find bo by cpu mapping
  (v2)")
Signed-off-by: Michel Dänzer 


Reviewed-by: Christian König 


---
  amdgpu/amdgpu_bo.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 86d1c143..8efd014e 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -551,14 +551,15 @@ int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle 
dev,
bo = handle_table_lookup(>bo_handles, i);
if (!bo || !bo->cpu_ptr || size > bo->alloc_size)
continue;
-   if (cpu >= bo->cpu_ptr && cpu < (bo->cpu_ptr + bo->alloc_size))
+   if (cpu >= bo->cpu_ptr &&
+   cpu < (void*)((uintptr_t)bo->cpu_ptr + bo->alloc_size))
break;
}
  
  	if (i < dev->bo_handles.max_key) {

atomic_inc(>refcount);
*buf_handle = bo;
-   *offset_in_bo = cpu - bo->cpu_ptr;
+   *offset_in_bo = (uintptr_t)cpu - (uintptr_t)bo->cpu_ptr;
} else {
*buf_handle = NULL;
*offset_in_bo = 0;


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v2 libdrm] amdgpu: Eliminate void* arithmetic in amdgpu_find_bo_by_cpu_mapping

2018-08-16 Thread Michel Dänzer
From: Michel Dänzer 

Arithmetic using void* pointers isn't defined by the C standard, only as
a GCC extension. Avoids compiler warnings:

../../amdgpu/amdgpu_bo.c: In function ‘amdgpu_find_bo_by_cpu_mapping’:
../../amdgpu/amdgpu_bo.c:554:48: warning: pointer of type ‘void *’ used in 
arithmetic [-Wpointer-arith]
   if (cpu >= bo->cpu_ptr && cpu < (bo->cpu_ptr + bo->alloc_size))
^
../../amdgpu/amdgpu_bo.c:561:23: warning: pointer of type ‘void *’ used in 
subtraction [-Wpointer-arith]
   *offset_in_bo = cpu - bo->cpu_ptr;
   ^

v2: Use uintptr_t instead of char*, don't change function signature
(Junwei Zhang)

Fixes: 4d454424e1f2 ("amdgpu: add a function to find bo by cpu mapping
 (v2)")
Signed-off-by: Michel Dänzer 
---
 amdgpu/amdgpu_bo.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 86d1c143..8efd014e 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -551,14 +551,15 @@ int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle 
dev,
bo = handle_table_lookup(>bo_handles, i);
if (!bo || !bo->cpu_ptr || size > bo->alloc_size)
continue;
-   if (cpu >= bo->cpu_ptr && cpu < (bo->cpu_ptr + bo->alloc_size))
+   if (cpu >= bo->cpu_ptr &&
+   cpu < (void*)((uintptr_t)bo->cpu_ptr + bo->alloc_size))
break;
}
 
if (i < dev->bo_handles.max_key) {
atomic_inc(>refcount);
*buf_handle = bo;
-   *offset_in_bo = cpu - bo->cpu_ptr;
+   *offset_in_bo = (uintptr_t)cpu - (uintptr_t)bo->cpu_ptr;
} else {
*buf_handle = NULL;
*offset_in_bo = 0;
-- 
2.18.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx