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 <funfunctor at folklore1984.net> --- amdgpu/amdgpu_bo.c | 2 +- amdgpu/amdgpu_cs.c | 36 +++++++++++------------------------- amdgpu/amdgpu_gpu_info.c | 5 +++-- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 9adfffa..5ac456b 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -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; diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c index fb5b3a8..7fbba96 100644 --- a/amdgpu/amdgpu_cs.c +++ b/amdgpu/amdgpu_cs.c @@ -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)) diff --git a/amdgpu/amdgpu_gpu_info.c b/amdgpu/amdgpu_gpu_info.c index f4b94c9..1efffc6 100644 --- a/amdgpu/amdgpu_gpu_info.c +++ b/amdgpu/amdgpu_gpu_info.c @@ -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, -- 2.9.3