amdgpu/: concisely && consistently check null ptrs in canonical form
Be consistent and use the canonical form while sanity checking null pointers, also combine a few branches for brevity.
--- amdgpu/amdgpu_bo.c | 2 +- amdgpu/amdgpu_cs.c | 36 +++++++++++------------------------- amdgpu/amdgpu_gpu_info.c | 5 +++-- 3 files changed, 15 insertions(+), 28 deletions(-)
amdgpu/amdgpu_bo.c +1 -1
@@ -652,7 +652,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,return -EINVAL ; list =malloc (number_of_resources *sizeof (struct drm_amdgpu_bo_list_entry )); -if (list ==NULL ) +if (!list)return -ENOMEM ; args.in.operation =AMDGPU_BO_LIST_OP_UPDATE ;
amdgpu/amdgpu_cs.c +11 -25
@@ -59,13 +59,11 @@ int amdgpu_cs_ctx_create(amdgpu_device_handle dev,int i, j, k;int r; -if (NULL == dev) -return -EINVAL ; -if (NULL == context) +if (!dev || !context)return -EINVAL ; gpu_context =calloc (1 ,sizeof (struct amdgpu_context )); -if (NULL == gpu_context) +if (!gpu_context)return -ENOMEM ; gpu_context->dev = dev;
@@ -110,7 +108,7 @@ int amdgpu_cs_ctx_free(amdgpu_context_handle context)int i, j, k;int r; -if (NULL == context) +if (!context)return -EINVAL ;pthread_mutex_destroy (&context->sequence_mutex);
@@ -330,9 +328,7 @@ int amdgpu_cs_submit(amdgpu_context_handle context,uint32_t i;int r; -if (NULL == context) -return -EINVAL ; -if (NULL == ibs_request) +if (!context || !ibs_request)return -EINVAL ; r =0 ;
@@ -416,11 +412,7 @@ int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence,bool busy = true;int r; -if (NULL == fence) -return -EINVAL ; -if (NULL == expired) -return -EINVAL ; -if (NULL == fence->context) +if (!fence || !expired || !fence->context)return -EINVAL ;if (fence->ip_type >=AMDGPU_HW_IP_NUM )return -EINVAL ;
@@ -447,11 +439,11 @@ int amdgpu_cs_create_semaphore(amdgpu_semaphore_handle *sem) {struct amdgpu_semaphore *gpu_semaphore; -if (NULL == sem) +if (!sem)return -EINVAL ; gpu_semaphore =calloc (1 ,sizeof (struct amdgpu_semaphore )); -if (NULL == gpu_semaphore) +if (!gpu_semaphore)return -ENOMEM ;atomic_set (&gpu_semaphore->refcount,1 );
@@ -466,14 +458,12 @@ int amdgpu_cs_signal_semaphore(amdgpu_context_handle ctx, uint32_t ring, amdgpu_semaphore_handle sem) { -if (NULL == ctx) +if (!ctx || !sem)return -EINVAL ;if (ip_type >=AMDGPU_HW_IP_NUM )return -EINVAL ;if (ring >=AMDGPU_CS_MAX_RINGS )return -EINVAL ; -if (NULL == sem) -return -EINVAL ;/* sem has been signaled */ if (sem->signal_fence.context)return -EINVAL ;
@@ -494,14 +484,12 @@ int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx, uint32_t ring, amdgpu_semaphore_handle sem) { -if (NULL == ctx) +if (!ctx || !sem)return -EINVAL ;if (ip_type >=AMDGPU_HW_IP_NUM )return -EINVAL ;if (ring >=AMDGPU_CS_MAX_RINGS )return -EINVAL ; -if (NULL == sem) -return -EINVAL ;/* must signal first */ if (NULL == sem->signal_fence.context)return -EINVAL ;
@@ -514,9 +502,7 @@ int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx,static int amdgpu_cs_reset_sem (amdgpu_semaphore_handle sem) { -if (NULL == sem) -return -EINVAL ; -if (NULL == sem->signal_fence.context) +if (!sem || !sem->signal_fence.context)return -EINVAL ; sem->signal_fence.context =NULL ;;
@@ -530,7 +516,7 @@ static int amdgpu_cs_reset_sem(amdgpu_semaphore_handle sem)static int amdgpu_cs_unreference_sem (amdgpu_semaphore_handle sem) { -if (NULL == sem) +if (!sem)return -EINVAL ;if (update_references (&sem->refcount,NULL ))
amdgpu/amdgpu_gpu_info.c +3 -2
@@ -234,8 +234,9 @@ drm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev)int amdgpu_query_gpu_info (amdgpu_device_handle dev,struct amdgpu_gpu_info *info) { -if ((dev ==NULL ) || (info ==NULL )) +if (!dev || !info)return -EINVAL ; +/* Get ASIC info*/ *info = dev->info;
@@ -300,7 +301,7 @@ int amdgpu_query_gds_info(amdgpu_device_handle dev,struct drm_amdgpu_info_gds gds_config = {};int r; -if (gds_info ==NULL ) +if (!gds_info)return -EINVAL ; r = amdgpu_query_info(dev, AMDGPU_INFO_GDS_CONFIG,
Signature · 6 lines
2.9.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20170418162032.16101-1-funfunctor-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org
Nicolai Hähnle
Reviewed-byQuoted 4 lines · Edward O'Callaghan
Be consistent and use the canonical form while sanity checking null pointers, also combine a few branches for brevity.
Signed-off-by Edward O'Callaghan <[email protected]>
Sure, it's a good cleanup. Feel free to add the corresponding change also to amdgpu_cs_wait_fences which I've already pushed.
Quoted 163 lines
--- amdgpu/amdgpu_bo.c | 2 +- amdgpu/amdgpu_cs.c | 36 +++++++++++------------------------- amdgpu/amdgpu_gpu_info.c | 5 +++-- 3 files changed, 15 insertions(+), 28 deletions(-)amdgpu/amdgpu_bo.c +1
-1@@ -652,7 +652,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,return -EINVAL ; list =malloc (number_of_resources *sizeof (struct drm_amdgpu_bo_list_entry )); -if (list ==NULL ) +if (!list)return -ENOMEM ; args.in.operation =AMDGPU_BO_LIST_OP_UPDATE ;amdgpu/amdgpu_cs.c +11
-25@@ -59,13 +59,11 @@ int amdgpu_cs_ctx_create(amdgpu_device_handle dev,int i, j, k;int r; -if (NULL == dev) -return -EINVAL ; -if (NULL == context) +if (!dev || !context)return -EINVAL ; gpu_context =calloc (1 ,sizeof (struct amdgpu_context )); -if (NULL == gpu_context) +if (!gpu_context)return -ENOMEM ; gpu_context->dev = dev;@@ -110,7 +108,7 @@ int amdgpu_cs_ctx_free(amdgpu_context_handle context)int i, j, k;int r; -if (NULL == context) +if (!context)return -EINVAL ;pthread_mutex_destroy (&context->sequence_mutex);@@ -330,9 +328,7 @@ int amdgpu_cs_submit(amdgpu_context_handle context,uint32_t i;int r; -if (NULL == context) -return -EINVAL ; -if (NULL == ibs_request) +if (!context || !ibs_request)return -EINVAL ; r =0 ;@@ -416,11 +412,7 @@ int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence,bool busy = true;int r; -if (NULL == fence) -return -EINVAL ; -if (NULL == expired) -return -EINVAL ; -if (NULL == fence->context) +if (!fence || !expired || !fence->context)return -EINVAL ;if (fence->ip_type >=AMDGPU_HW_IP_NUM )return -EINVAL ;@@ -447,11 +439,11 @@ int amdgpu_cs_create_semaphore(amdgpu_semaphore_handle *sem) {struct amdgpu_semaphore *gpu_semaphore; -if (NULL == sem) +if (!sem)return -EINVAL ; gpu_semaphore =calloc (1 ,sizeof (struct amdgpu_semaphore )); -if (NULL == gpu_semaphore) +if (!gpu_semaphore)return -ENOMEM ;atomic_set (&gpu_semaphore->refcount,1 );@@ -466,14 +458,12 @@ int amdgpu_cs_signal_semaphore(amdgpu_context_handle ctx, uint32_t ring, amdgpu_semaphore_handle sem) { -if (NULL == ctx) +if (!ctx || !sem)return -EINVAL ;if (ip_type >=AMDGPU_HW_IP_NUM )return -EINVAL ;if (ring >=AMDGPU_CS_MAX_RINGS )return -EINVAL ; -if (NULL == sem) -return -EINVAL ;/* sem has been signaled */ if (sem->signal_fence.context)return -EINVAL ;@@ -494,14 +484,12 @@ int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx, uint32_t ring, amdgpu_semaphore_handle sem) { -if (NULL == ctx) +if (!ctx || !sem)return -EINVAL ;if (ip_type >=AMDGPU_HW_IP_NUM )return -EINVAL ;if (ring >=AMDGPU_CS_MAX_RINGS )return -EINVAL ; -if (NULL == sem) -return -EINVAL ;/* must signal first */ if (NULL == sem->signal_fence.context)return -EINVAL ;@@ -514,9 +502,7 @@ int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx,static int amdgpu_cs_reset_sem (amdgpu_semaphore_handle sem) { -if (NULL == sem) -return -EINVAL ; -if (NULL == sem->signal_fence.context) +if (!sem || !sem->signal_fence.context)return -EINVAL ; sem->signal_fence.context =NULL ;;@@ -530,7 +516,7 @@ static int amdgpu_cs_reset_sem(amdgpu_semaphore_handle sem)static int amdgpu_cs_unreference_sem (amdgpu_semaphore_handle sem) { -if (NULL == sem) +if (!sem)return -EINVAL ;if (update_references (&sem->refcount,NULL ))amdgpu/amdgpu_gpu_info.c +3
-2@@ -234,8 +234,9 @@ drm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev)int amdgpu_query_gpu_info (amdgpu_device_handle dev,struct amdgpu_gpu_info *info) { -if ((dev ==NULL ) || (info ==NULL )) +if (!dev || !info)return -EINVAL ; +/* Get ASIC info*/ *info = dev->info;@@ -300,7 +301,7 @@ int amdgpu_query_gds_info(amdgpu_device_handle dev,struct drm_amdgpu_info_gds gds_config = {};int r; -if (gds_info ==NULL ) +if (!gds_info)return -EINVAL ; r = amdgpu_query_info(dev, AMDGPU_INFO_GDS_CONFIG,
Signature · 6 lines
Lerne, wie die Welt wirklich ist, Aber vergiss niemals, wie sie sein sollte. _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Hi Edward,
On 18 April 2017 at 17:20, Edward O'Callaghan
<[email protected]> wrote:
[snip]
Quoted 2 lines
if (NULL == sem->signal_fence.context)
return -EINVAL;I think this hunk can be fixed as well.
-Emi
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx