Re: [PATCH libdrm 2/2] amdgpu: Use char* pointers in amdgpu_find_bo_by_cpu_mapping
On 2018-08-15 03:07 AM, Zhang, Jerry (Junwei) wrote: > On 08/14/2018 05:58 PM, Michel Dänzer wrote: >> 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; >> ^ >> >> Fixes: 4d454424e1f2 ("amdgpu: add a function to find bo by cpu mapping >> (v2)") >> Signed-off-by: Michel Dänzer >> --- >> amdgpu/amdgpu.h | 2 +- >> amdgpu/amdgpu_bo.c | 7 --- >> 2 files changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h >> index a8c353c6..f2bdeb95 100644 >> --- a/amdgpu/amdgpu.h >> +++ b/amdgpu/amdgpu.h >> @@ -695,7 +695,7 @@ int >> amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, >> * >> */ >> int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, >> - void *cpu, >> + char *cpu, > > Shall we cast the cpu pointer when do arithmetic and keep the arguments > as other cpu ponter? > > e.g. > @@ -565,14 +565,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 && > + (uint64_t)cpu < ((uint64_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 = (uint64_t)cpu - (uint64_t)bo->cpu_ptr; > } else { > *buf_handle = NULL; > *offset_in_bo = 0; Thanks for the suggestion, I sent out a v2 patch along those lines (though slightly different). -- Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer ___ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH libdrm 2/2] amdgpu: Use char* pointers in amdgpu_find_bo_by_cpu_mapping
On 08/14/2018 05:58 PM, Michel Dänzer wrote: 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; ^ Fixes: 4d454424e1f2 ("amdgpu: add a function to find bo by cpu mapping (v2)") Signed-off-by: Michel Dänzer --- amdgpu/amdgpu.h| 2 +- amdgpu/amdgpu_bo.c | 7 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h index a8c353c6..f2bdeb95 100644 --- a/amdgpu/amdgpu.h +++ b/amdgpu/amdgpu.h @@ -695,7 +695,7 @@ int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, * */ int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, - void *cpu, + char *cpu, Shall we cast the cpu pointer when do arithmetic and keep the arguments as other cpu ponter? e.g. @@ -565,14 +565,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 && + (uint64_t)cpu < ((uint64_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 = (uint64_t)cpu - (uint64_t)bo->cpu_ptr; } else { *buf_handle = NULL; *offset_in_bo = 0; Regards, Jerry uint64_t size, amdgpu_bo_handle *buf_handle, uint64_t *offset_in_bo); diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 86d1c143..ef75f1d0 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -530,7 +530,7 @@ int amdgpu_bo_wait_for_idle(amdgpu_bo_handle bo, } int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, - void *cpu, + char *cpu, uint64_t size, amdgpu_bo_handle *buf_handle, uint64_t *offset_in_bo) @@ -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 >= (char*)bo->cpu_ptr && + cpu < ((char*)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 = cpu - (char*)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 libdrm 2/2] amdgpu: Use char* pointers 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; ^ Fixes: 4d454424e1f2 ("amdgpu: add a function to find bo by cpu mapping (v2)") Signed-off-by: Michel Dänzer --- amdgpu/amdgpu.h| 2 +- amdgpu/amdgpu_bo.c | 7 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h index a8c353c6..f2bdeb95 100644 --- a/amdgpu/amdgpu.h +++ b/amdgpu/amdgpu.h @@ -695,7 +695,7 @@ int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, * */ int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, - void *cpu, + char *cpu, uint64_t size, amdgpu_bo_handle *buf_handle, uint64_t *offset_in_bo); diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 86d1c143..ef75f1d0 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -530,7 +530,7 @@ int amdgpu_bo_wait_for_idle(amdgpu_bo_handle bo, } int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, - void *cpu, + char *cpu, uint64_t size, amdgpu_bo_handle *buf_handle, uint64_t *offset_in_bo) @@ -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 >= (char*)bo->cpu_ptr && + cpu < ((char*)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 = cpu - (char*)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