From 4de2add5e9d03bee524fcdfd9d91c14025cbb384 Mon Sep 17 00:00:00 2001 From: Amurthyreddy Date: Mon, 5 Nov 2018 15:38:44 +0530 Subject: [PATCH] gpu: nvgpu: MISRA 14.4 boolean fixes MISRA rule 14.4 doesn't allow the usage of non-boolean variable as boolean in the controlling expression of an if statement or an iteration statement. Fix violations where a non-boolean variable is used as a boolean in the controlling expression of if and loop statements. JIRA NVGPU-1022 Change-Id: Ia96f3bc6ca645ba8538faf7a9fa3a9ccf9df40d3 Signed-off-by: Amurthyreddy Reviewed-on: https://git-master.nvidia.com/r/1943168 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/ce2.c | 6 +-- .../gpu/nvgpu/common/mm/bitmap_allocator.c | 4 +- drivers/gpu/nvgpu/common/mm/buddy_allocator.c | 16 +++---- drivers/gpu/nvgpu/common/mm/dma.c | 2 +- drivers/gpu/nvgpu/common/mm/gmmu.c | 28 ++++++------- .../gpu/nvgpu/common/mm/lockless_allocator.c | 2 +- drivers/gpu/nvgpu/common/mm/mm.c | 2 +- drivers/gpu/nvgpu/common/mm/nvgpu_mem.c | 2 +- drivers/gpu/nvgpu/common/mm/page_allocator.c | 28 ++++++------- drivers/gpu/nvgpu/common/mm/pd_cache.c | 4 +- drivers/gpu/nvgpu/common/mm/vm.c | 26 ++++++------ drivers/gpu/nvgpu/common/mm/vm_area.c | 4 +- drivers/gpu/nvgpu/common/pramin.c | 11 +++-- drivers/gpu/nvgpu/common/rbtree.c | 42 ++++++++++--------- drivers/gpu/nvgpu/common/semaphore.c | 6 +-- drivers/gpu/nvgpu/gv100/gr_gv100.c | 2 +- 16 files changed, 95 insertions(+), 90 deletions(-) diff --git a/drivers/gpu/nvgpu/common/ce2.c b/drivers/gpu/nvgpu/common/ce2.c index dc31fc511..b6b3fa797 100644 --- a/drivers/gpu/nvgpu/common/ce2.c +++ b/drivers/gpu/nvgpu/common/ce2.c @@ -100,7 +100,7 @@ int gk20a_ce_execute_ops(struct gk20a *g, cmd_buf_cpu_va = (u32 *)ce_ctx->cmd_buf_mem.cpu_va; - if (ce_ctx->postfences[ce_ctx->cmd_buf_read_queue_offset]) { + if (ce_ctx->postfences[ce_ctx->cmd_buf_read_queue_offset] != NULL) { struct gk20a_fence **prev_post_fence = &ce_ctx->postfences[ce_ctx->cmd_buf_read_queue_offset]; @@ -127,7 +127,7 @@ int gk20a_ce_execute_ops(struct gk20a *g, request_operation, dma_copy_class); - if (methodSize) { + if (methodSize != 0U) { /* store the element into gpfifo */ gpfifo.entry0 = u64_lo32(cmd_buf_gpu_va); @@ -146,7 +146,7 @@ int gk20a_ce_execute_ops(struct gk20a *g, if (ret == 0) { ce_ctx->postfences[ce_ctx->cmd_buf_read_queue_offset] = ce_cmd_buf_fence_out; - if (gk20a_fence_out) { + if (gk20a_fence_out != NULL) { gk20a_fence_get(ce_cmd_buf_fence_out); *gk20a_fence_out = ce_cmd_buf_fence_out; } diff --git a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c index a1dc207ff..ed34271d7 100644 --- a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c @@ -316,7 +316,7 @@ static void nvgpu_bitmap_alloc_destroy(struct nvgpu_allocator *na) * Kill any outstanding allocations. */ nvgpu_rbtree_enum_start(0, &node, a->allocs); - while (node) { + while (node != NULL) { alloc = nvgpu_bitmap_alloc_from_rbtree_node(node); nvgpu_rbtree_unlink(node, &a->allocs); @@ -450,7 +450,7 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return 0; fail: - if (a->meta_data_cache) { + if (a->meta_data_cache != NULL) { nvgpu_kmem_cache_destroy(a->meta_data_cache); } nvgpu_kfree(g, a); diff --git a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c b/drivers/gpu/nvgpu/common/mm/buddy_allocator.c index 43253c4bb..c6507f29d 100644 --- a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/buddy_allocator.c @@ -292,7 +292,7 @@ static void nvgpu_buddy_allocator_destroy(struct nvgpu_allocator *na) * Free the fixed allocs first. */ nvgpu_rbtree_enum_start(0, &node, a->fixed_allocs); - while (node) { + while (node != NULL) { falloc = nvgpu_fixed_alloc_from_rbtree_node(node); nvgpu_rbtree_unlink(node, &a->fixed_allocs); @@ -305,7 +305,7 @@ static void nvgpu_buddy_allocator_destroy(struct nvgpu_allocator *na) * And now free all outstanding allocations. */ nvgpu_rbtree_enum_start(0, &node, a->alloced_buddies); - while (node) { + while (node != NULL) { bud = nvgpu_buddy_from_rbtree_node(node); (void) balloc_free_buddy(a, bud->start); @@ -564,7 +564,7 @@ static u64 balloc_do_alloc(struct nvgpu_buddy_allocator *a, } while (bud->order != order) { - if (balloc_split_buddy(a, bud, pte_size)) { + if (balloc_split_buddy(a, bud, pte_size) != 0) { return 0; /* No mem... */ } bud = bud->left; @@ -686,7 +686,7 @@ static struct nvgpu_buddy *balloc_make_fixed_buddy( * make. */ while (cur_order <= a->max_order) { - int found = 0; + bool found = false; order_list = balloc_get_order_list(a, cur_order); nvgpu_list_for_each_entry(bud, order_list, @@ -706,7 +706,7 @@ static struct nvgpu_buddy *balloc_make_fixed_buddy( return NULL; } - found = 1; + found = true; break; } } @@ -726,7 +726,7 @@ static struct nvgpu_buddy *balloc_make_fixed_buddy( /* Split this buddy as necessary until we get the target buddy. */ while (bud->start != base || bud->order != order) { - if (balloc_split_buddy(a, bud, pte_size)) { + if (balloc_split_buddy(a, bud, pte_size) != 0) { alloc_dbg(balloc_owner(a), "split buddy failed? {0x%llx, %llu}", bud->start, bud->order); @@ -1015,7 +1015,7 @@ static void nvgpu_buddy_bfree(struct nvgpu_allocator *na, u64 addr) * buddy. */ falloc = balloc_free_fixed(a, addr); - if (falloc) { + if (falloc != NULL) { balloc_do_free_fixed(a, falloc); goto done; } @@ -1402,7 +1402,7 @@ int nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return 0; fail: - if (a->buddy_cache) { + if (a->buddy_cache != NULL) { nvgpu_kmem_cache_destroy(a->buddy_cache); } nvgpu_kfree(g, a); diff --git a/drivers/gpu/nvgpu/common/mm/dma.c b/drivers/gpu/nvgpu/common/mm/dma.c index 47edc24be..98b4e9962 100644 --- a/drivers/gpu/nvgpu/common/mm/dma.c +++ b/drivers/gpu/nvgpu/common/mm/dma.c @@ -197,7 +197,7 @@ void nvgpu_dma_free(struct gk20a *g, struct nvgpu_mem *mem) void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem) { - if (mem->gpu_va) { + if (mem->gpu_va != 0ULL) { nvgpu_gmmu_unmap(vm, mem, mem->gpu_va); } mem->gpu_va = 0; diff --git a/drivers/gpu/nvgpu/common/mm/gmmu.c b/drivers/gpu/nvgpu/common/mm/gmmu.c index e6a76d42c..bbea3df19 100644 --- a/drivers/gpu/nvgpu/common/mm/gmmu.c +++ b/drivers/gpu/nvgpu/common/mm/gmmu.c @@ -276,7 +276,7 @@ static int pd_allocate(struct vm_gk20a *vm, { int err; - if (pd->mem) { + if (pd->mem != NULL) { return 0; } @@ -320,7 +320,7 @@ static int pd_allocate_children(struct vm_gk20a *vm, { struct gk20a *g = gk20a_from_vm(vm); - if (pd->entries) { + if (pd->entries != NULL) { return 0; } @@ -392,7 +392,7 @@ static int __set_pd_level(struct vm_gk20a *vm, * For each of those chunks program our level's PDE and then, if there's * a next level, program the next level's PDEs/PTEs. */ - while (length) { + while (length != 0ULL) { u32 pd_idx = pd_index(l, virt_addr, attrs); u64 chunk_size; u64 target_addr; @@ -409,8 +409,8 @@ static int __set_pd_level(struct vm_gk20a *vm, * that _this_ level points to PDEs (not PTEs). Thus we need to * have a bunch of children PDs. */ - if (next_l->update_entry) { - if (pd_allocate_children(vm, l, pd, attrs)) { + if (next_l->update_entry != NULL) { + if (pd_allocate_children(vm, l, pd, attrs) != 0) { return -ENOMEM; } @@ -425,7 +425,7 @@ static int __set_pd_level(struct vm_gk20a *vm, /* * Allocate the backing memory for next_pd. */ - if (pd_allocate(vm, next_pd, next_l, attrs)) { + if (pd_allocate(vm, next_pd, next_l, attrs) != 0) { return -ENOMEM; } } @@ -446,7 +446,7 @@ static int __set_pd_level(struct vm_gk20a *vm, target_addr, attrs); - if (next_l->update_entry) { + if (next_l->update_entry != NULL) { err = __set_pd_level(vm, next_pd, lvl + 1, phys_addr, @@ -467,7 +467,7 @@ static int __set_pd_level(struct vm_gk20a *vm, * non-zero phys addresses in the PTEs. A non-zero phys-addr * would also confuse the lower level PTE programming code. */ - if (phys_addr) { + if (phys_addr != 0ULL) { phys_addr += chunk_size; } length -= chunk_size; @@ -777,7 +777,7 @@ u64 gk20a_locked_gmmu_map(struct vm_gk20a *vm, * the programmed ctagline gets increased at compression_page_size * boundaries. */ - if (attrs.ctag) { + if (attrs.ctag != 0ULL) { attrs.ctag += buffer_offset & (U64(ctag_granularity) - U64(1)); } @@ -919,7 +919,7 @@ static int __nvgpu_locate_pte(struct gk20a *g, struct vm_gk20a *vm, * If this isn't the final level (i.e there's a valid next level) * then find the next level PD and recurse. */ - if (next_l->update_entry) { + if (next_l->update_entry != NULL) { struct nvgpu_gmmu_pd *pd_next = pd->entries + pd_idx; /* Invalid entry! */ @@ -951,21 +951,21 @@ static int __nvgpu_locate_pte(struct gk20a *g, struct vm_gk20a *vm, pd_offset_from_index(l, pd_idx); pte_size = (u32)(l->entry_size / sizeof(u32)); - if (data) { + if (data != NULL) { for (i = 0; i < pte_size; i++) { data[i] = nvgpu_mem_rd32(g, pd->mem, pte_base + i); } } - if (pd_out) { + if (pd_out != NULL) { *pd_out = pd; } - if (pd_idx_out) { + if (pd_idx_out != NULL) { *pd_idx_out = pd_idx; } - if (pd_offs_out) { + if (pd_offs_out != NULL) { *pd_offs_out = pd_offset_from_index(l, pd_idx); } diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c index 3d540100a..1f42e1b37 100644 --- a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c @@ -81,7 +81,7 @@ static u64 nvgpu_lockless_alloc(struct nvgpu_allocator *a, u64 len) head = NV_ACCESS_ONCE(pa->head); } - if (addr) { + if (addr != 0ULL) { alloc_dbg(a, "Alloc node # %d @ addr 0x%llx", head, addr); } else { alloc_dbg(a, "Alloc failed!"); diff --git a/drivers/gpu/nvgpu/common/mm/mm.c b/drivers/gpu/nvgpu/common/mm/mm.c index 84f88ce27..b78085efb 100644 --- a/drivers/gpu/nvgpu/common/mm/mm.c +++ b/drivers/gpu/nvgpu/common/mm/mm.c @@ -103,7 +103,7 @@ u32 nvgpu_vm_get_pte_size(struct vm_gk20a *vm, u64 base, u64 size) return nvgpu_vm_get_pte_size_split_addr(vm, base, size); } - if (base) { + if (base != 0ULL) { return nvgpu_vm_get_pte_size_fixed_map(vm, base, size); } diff --git a/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c b/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c index 6154f5deb..0a1e91998 100644 --- a/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c +++ b/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c @@ -190,7 +190,7 @@ u64 nvgpu_sgt_alignment(struct gk20a *g, struct nvgpu_sgt *sgt) chunk_align = 1ULL << __ffs(nvgpu_sgt_get_phys(g, sgt, sgl) | nvgpu_sgt_get_length(sgt, sgl)); - if (align) { + if (align != 0ULL) { align = min(align, chunk_align); } else { align = chunk_align; diff --git a/drivers/gpu/nvgpu/common/mm/page_allocator.c b/drivers/gpu/nvgpu/common/mm/page_allocator.c index c9fa929b9..92e270376 100644 --- a/drivers/gpu/nvgpu/common/mm/page_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/page_allocator.c @@ -227,7 +227,7 @@ static void nvgpu_page_alloc_sgl_proper_free(struct gk20a *g, { struct nvgpu_mem_sgl *next; - while (sgl) { + while (sgl != NULL) { next = sgl->next; nvgpu_kfree(g, sgl); sgl = next; @@ -242,7 +242,7 @@ static void nvgpu_page_alloc_free_pages(struct nvgpu_page_allocator *a, struct gk20a *g = a->owner->g; if (free_buddy_alloc) { - while (sgl) { + while (sgl != NULL) { nvgpu_free(&a->source_allocator, nvgpu_sgt_get_phys(g, &alloc->sgt, sgl)); sgl = nvgpu_sgt_get_next(&alloc->sgt, sgl); @@ -456,10 +456,10 @@ static struct nvgpu_page_alloc *nvgpu_alloc_slab( return alloc; fail: - if (alloc) { + if (alloc != NULL) { nvgpu_kmem_cache_free(a->alloc_cache, alloc); } - if (sgl) { + if (sgl != NULL) { nvgpu_kfree(a->owner->g, sgl); } return NULL; @@ -540,7 +540,7 @@ static struct nvgpu_page_alloc *do_nvgpu_alloc_pages( alloc->length = pages << a->page_shift; alloc->sgt.ops = &page_alloc_sgl_ops; - while (pages) { + while (pages != 0ULL) { u64 chunk_addr = 0; u64 chunk_pages = (u64)1 << __fls(pages); u64 chunk_len = chunk_pages << a->page_shift; @@ -601,7 +601,7 @@ static struct nvgpu_page_alloc *do_nvgpu_alloc_pages( * Build the singly linked list with a head node that is part of * the list. */ - if (prev_sgl) { + if (prev_sgl != NULL) { prev_sgl->next = sgl; } else { alloc->sgt.sgl = (struct nvgpu_sgl *)sgl; @@ -619,7 +619,7 @@ static struct nvgpu_page_alloc *do_nvgpu_alloc_pages( fail_cleanup: sgl = (struct nvgpu_mem_sgl *)alloc->sgt.sgl; - while (sgl) { + while (sgl != NULL) { struct nvgpu_mem_sgl *next = sgl->next; nvgpu_free(&a->source_allocator, sgl->phys); @@ -654,7 +654,7 @@ static struct nvgpu_page_alloc *nvgpu_alloc_pages( palloc_dbg(a, "Alloc 0x%llx (%llu) id=0x%010llx", pages << a->page_shift, pages, alloc->base); sgl = alloc->sgt.sgl; - while (sgl) { + while (sgl != NULL) { palloc_dbg(a, " Chunk %2d: 0x%010llx + 0x%llx", i++, nvgpu_sgt_get_phys(g, &alloc->sgt, sgl), @@ -748,7 +748,7 @@ static void nvgpu_page_free(struct nvgpu_allocator *na, u64 base) /* * Frees *alloc. */ - if (alloc->slab_page) { + if (alloc->slab_page != NULL) { nvgpu_free_slab(a, alloc); } else { a->pages_freed += (alloc->length >> a->page_shift); @@ -791,10 +791,10 @@ static struct nvgpu_page_alloc *nvgpu_alloc_pages_fixed( return alloc; fail: - if (sgl) { + if (sgl != NULL) { nvgpu_kfree(a->owner->g, sgl); } - if (alloc) { + if (alloc != NULL) { nvgpu_kmem_cache_free(a->alloc_cache, alloc); } return NULL; @@ -830,7 +830,7 @@ static u64 nvgpu_page_alloc_fixed(struct nvgpu_allocator *na, palloc_dbg(a, "Alloc [fixed] @ 0x%010llx + 0x%llx (%llu)", alloc->base, aligned_len, pages); sgl = alloc->sgt.sgl; - while (sgl) { + while (sgl != NULL) { palloc_dbg(a, " Chunk %2d: 0x%010llx + 0x%llx", i++, nvgpu_sgt_get_phys(g, &alloc->sgt, sgl), @@ -1082,10 +1082,10 @@ int nvgpu_page_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, return 0; fail: - if (a->alloc_cache) { + if (a->alloc_cache != NULL) { nvgpu_kmem_cache_destroy(a->alloc_cache); } - if (a->slab_page_cache) { + if (a->slab_page_cache != NULL) { nvgpu_kmem_cache_destroy(a->slab_page_cache); } nvgpu_kfree(g, a); diff --git a/drivers/gpu/nvgpu/common/mm/pd_cache.c b/drivers/gpu/nvgpu/common/mm/pd_cache.c index ac87ccd24..3ce8d40c1 100644 --- a/drivers/gpu/nvgpu/common/mm/pd_cache.c +++ b/drivers/gpu/nvgpu/common/mm/pd_cache.c @@ -169,7 +169,7 @@ int nvgpu_pd_cache_init(struct gk20a *g) * This gets called from finalize_poweron() so we need to make sure we * don't reinit the pd_cache over and over. */ - if (g->mm.pd_cache) { + if (g->mm.pd_cache != NULL) { return 0; } @@ -284,7 +284,7 @@ static int nvgpu_pd_cache_alloc_new(struct gk20a *g, return -ENOMEM; } - if (nvgpu_dma_alloc(g, PAGE_SIZE, &pentry->mem)) { + if (nvgpu_dma_alloc(g, PAGE_SIZE, &pentry->mem) != 0) { nvgpu_kfree(g, pentry); nvgpu_err(g, "Unable to DMA alloc!"); return -ENOMEM; diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index 9046205a5..b5218af18 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c @@ -75,7 +75,7 @@ int nvgpu_vm_pde_coverage_bit_count(struct vm_gk20a *vm) * heirarchy: the last level is PTEs so we really want the level * before that which is the last level of PDEs. */ - while (vm->mmu_levels[final_pde_level + 2].update_entry) { + while (vm->mmu_levels[final_pde_level + 2].update_entry != NULL) { final_pde_level++; } @@ -88,12 +88,12 @@ static void __nvgpu_vm_free_entries(struct vm_gk20a *vm, { int i; - if (pd->mem) { + if (pd->mem != NULL) { nvgpu_pd_free(vm, pd); pd->mem = NULL; } - if (pd->entries) { + if (pd->entries != NULL) { for (i = 0; i < pd->num_entries; i++) { __nvgpu_vm_free_entries(vm, &pd->entries[i], level + 1); @@ -227,7 +227,7 @@ static int nvgpu_init_sema_pool(struct vm_gk20a *vm) return 0; } - if (vm->sema_pool) { + if (vm->sema_pool != NULL) { return 0; } @@ -586,7 +586,7 @@ struct vm_gk20a *nvgpu_vm_init(struct gk20a *g, if (__nvgpu_vm_init(&g->mm, vm, big_page_size, low_hole, kernel_reserved, aperture_size, big_pages, - userspace_managed, name)) { + userspace_managed, name) != 0) { nvgpu_kfree(g, vm); return NULL; } @@ -610,7 +610,7 @@ static void __nvgpu_vm_remove(struct vm_gk20a *vm) * update_gmmu_lock. */ if (!nvgpu_has_syncpoints(g)) { - if (vm->sema_pool) { + if (vm->sema_pool != NULL) { nvgpu_semaphore_pool_unmap(vm->sema_pool, vm); nvgpu_semaphore_pool_put(vm->sema_pool); } @@ -625,7 +625,7 @@ static void __nvgpu_vm_remove(struct vm_gk20a *vm) nvgpu_mutex_acquire(&vm->update_gmmu_lock); nvgpu_rbtree_enum_start(0, &node, vm->mapped_buffers); - while (node) { + while (node != NULL) { mapped_buffer = mapped_buffer_from_rbtree_node(node); __nvgpu_vm_unmap(mapped_buffer, NULL); nvgpu_rbtree_enum_start(0, &node, vm->mapped_buffers); @@ -765,7 +765,7 @@ int nvgpu_vm_get_buffers(struct vm_gk20a *vm, } nvgpu_rbtree_enum_start(0, &node, vm->mapped_buffers); - while (node) { + while (node != NULL) { mapped_buffer = mapped_buffer_from_rbtree_node(node); buffer_list[i] = mapped_buffer; nvgpu_ref_get(&mapped_buffer->ref); @@ -877,7 +877,7 @@ struct nvgpu_mapped_buf *nvgpu_vm_map(struct vm_gk20a *vm, map_key_kind); nvgpu_mutex_release(&vm->update_gmmu_lock); - if (mapped_buffer) { + if (mapped_buffer != NULL) { nvgpu_ref_get(&mapped_buffer->ref); return mapped_buffer; } @@ -1004,7 +1004,7 @@ struct nvgpu_mapped_buf *nvgpu_vm_map(struct vm_gk20a *vm, /* * Store the ctag offset for later use if we got the comptags */ - if (comptags.lines) { + if (comptags.lines != 0U) { ctag_offset = comptags.offset; } } @@ -1080,7 +1080,7 @@ struct nvgpu_mapped_buf *nvgpu_vm_map(struct vm_gk20a *vm, goto clean_up; } - if (vm_area) { + if (vm_area != NULL) { nvgpu_list_add_tail(&mapped_buffer->buffer_list, &vm_area->buffer_list_head); mapped_buffer->vm_area = vm_area; @@ -1091,7 +1091,7 @@ struct nvgpu_mapped_buf *nvgpu_vm_map(struct vm_gk20a *vm, return mapped_buffer; clean_up: - if (mapped_buffer->addr) { + if (mapped_buffer->addr != 0ULL) { g->ops.mm.gmmu_unmap(vm, mapped_buffer->addr, mapped_buffer->size, @@ -1213,7 +1213,7 @@ void nvgpu_vm_unmap(struct vm_gk20a *vm, u64 offset, } if (mapped_buffer->flags & NVGPU_VM_MAP_FIXED_OFFSET) { - if (nvgpu_vm_unmap_sync_buffer(vm, mapped_buffer)) { + if (nvgpu_vm_unmap_sync_buffer(vm, mapped_buffer) != 0) { /* * Looks like we have failed... Better not continue in * case the buffer is in use. diff --git a/drivers/gpu/nvgpu/common/mm/vm_area.c b/drivers/gpu/nvgpu/common/mm/vm_area.c index 2fc64dbc1..0acc22865 100644 --- a/drivers/gpu/nvgpu/common/mm/vm_area.c +++ b/drivers/gpu/nvgpu/common/mm/vm_area.c @@ -198,10 +198,10 @@ int nvgpu_vm_area_alloc(struct vm_gk20a *vm, u32 pages, u32 page_size, return 0; clean_up_err: - if (vaddr_start) { + if (vaddr_start != 0ULL) { nvgpu_free(vma, vaddr_start); } - if (vm_area) { + if (vm_area != NULL) { nvgpu_kfree(g, vm_area); } return -ENOMEM; diff --git a/drivers/gpu/nvgpu/common/pramin.c b/drivers/gpu/nvgpu/common/pramin.c index b232a048f..84caf1a23 100644 --- a/drivers/gpu/nvgpu/common/pramin.c +++ b/drivers/gpu/nvgpu/common/pramin.c @@ -68,7 +68,7 @@ static void nvgpu_pramin_access_batched(struct gk20a *g, struct nvgpu_mem *mem, } } - while (size) { + while (size != 0U) { u32 sgl_len; BUG_ON(sgl == NULL); @@ -105,7 +105,8 @@ static void nvgpu_pramin_access_batch_rd_n(struct gk20a *g, { u32 r = start, *dest_u32 = *arg; - while (words--) { + while (words != 0U) { + words--; *dest_u32++ = nvgpu_readl(g, r); r += sizeof(u32); } @@ -127,7 +128,8 @@ static void nvgpu_pramin_access_batch_wr_n(struct gk20a *g, { u32 r = start, *src_u32 = *arg; - while (words--) { + while (words != 0U) { + words--; nvgpu_writel_relaxed(g, r, *src_u32++); r += sizeof(u32); } @@ -149,7 +151,8 @@ static void nvgpu_pramin_access_batch_set(struct gk20a *g, { u32 r = start, repeat = **arg; - while (words--) { + while (words != 0U) { + words--; nvgpu_writel_relaxed(g, r, repeat); r += sizeof(u32); } diff --git a/drivers/gpu/nvgpu/common/rbtree.c b/drivers/gpu/nvgpu/common/rbtree.c index 33735a4ff..e03cba5fb 100644 --- a/drivers/gpu/nvgpu/common/rbtree.c +++ b/drivers/gpu/nvgpu/common/rbtree.c @@ -32,13 +32,13 @@ static void rotate_left(struct nvgpu_rbtree_node **root, /* establish x->right link */ x->right = y->left; - if (y->left) { + if (y->left != NULL) { y->left->parent = x; } /* establish y->parent link */ y->parent = x->parent; - if (x->parent) { + if (x->parent != NULL) { if (x == x->parent->left) { x->parent->left = y; } else { @@ -63,13 +63,13 @@ static void rotate_right(struct nvgpu_rbtree_node **root, /* establish x->left link */ x->left = y->right; - if (y->right) { + if (y->right != NULL) { y->right->parent = x; } /* establish y->parent link */ y->parent = x->parent; - if (x->parent) { + if (x->parent != NULL) { if (x == x->parent->right) { x->parent->right = y; } else { @@ -151,7 +151,7 @@ void nvgpu_rbtree_insert(struct nvgpu_rbtree_node *new_node, curr = *root; parent = NULL; - while (curr) { + while (curr != NULL) { parent = curr; if (new_node->key_start < curr->key_start) { curr = curr->left; @@ -169,7 +169,7 @@ void nvgpu_rbtree_insert(struct nvgpu_rbtree_node *new_node, new_node->is_red = true; /* insert node in tree */ - if (parent) { + if (parent != NULL) { if (new_node->key_start < parent->key_start) { parent->left = new_node; } else { @@ -282,13 +282,13 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node, } else { /* find tree successor */ y = z->right; - while (y->left) { + while (y->left != NULL) { y = y->left; } } /* x is y's only child */ - if (y->left) { + if (y->left != NULL) { x = y->left; } else { x = y->right; @@ -300,7 +300,7 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node, x->parent = parent_of_x; } - if (y->parent) { + if (y->parent != NULL) { if (y == y->parent->left) { y->parent->left = x; } else { @@ -316,7 +316,7 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node, * the memory for z can be freed */ y->parent = z->parent; - if (z->parent) { + if (z->parent != NULL) { if (z == z->parent->left) { z->parent->left = y; } else { @@ -329,12 +329,12 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node, y->is_red = z->is_red; y->left = z->left; - if (z->left) { + if (z->left != NULL) { z->left->parent = y; } y->right = z->right; - if (z->right) { + if (z->right != NULL) { z->right->parent = y; } @@ -353,7 +353,7 @@ void nvgpu_rbtree_search(u64 key_start, struct nvgpu_rbtree_node **node, { struct nvgpu_rbtree_node *curr = root; - while (curr) { + while (curr != NULL) { if (key_start < curr->key_start) { curr = curr->left; } else if (key_start > curr->key_start) { @@ -373,7 +373,7 @@ void nvgpu_rbtree_range_search(u64 key, { struct nvgpu_rbtree_node *curr = root; - while (curr) { + while (curr != NULL) { if (key >= curr->key_start && key < curr->key_end) { *node = curr; @@ -394,7 +394,7 @@ void nvgpu_rbtree_less_than_search(u64 key_start, { struct nvgpu_rbtree_node *curr = root; - while (curr) { + while (curr != NULL) { if (key_start <= curr->key_start) { curr = curr->left; } else { @@ -409,10 +409,10 @@ void nvgpu_rbtree_enum_start(u64 key_start, struct nvgpu_rbtree_node **node, { *node = NULL; - if (root) { + if (root != NULL) { struct nvgpu_rbtree_node *curr = root; - while (curr) { + while (curr != NULL) { if (key_start < curr->key_start) { *node = curr; curr = curr->left; @@ -436,14 +436,16 @@ void nvgpu_rbtree_enum_next(struct nvgpu_rbtree_node **node, curr = *node; /* pick the leftmost node of the right subtree ? */ - if (curr->right) { + if (curr->right != NULL) { curr = curr->right; - for (; curr->left;) { + for (; curr->left != NULL;) { curr = curr->left; } } else { /* go up until we find the right inorder node */ - for (curr = curr->parent; curr; curr = curr->parent) { + for (curr = curr->parent; + curr != NULL; + curr = curr->parent) { if (curr->key_start > (*node)->key_start) { break; } diff --git a/drivers/gpu/nvgpu/common/semaphore.c b/drivers/gpu/nvgpu/common/semaphore.c index e3672dc05..ca8ea7bbe 100644 --- a/drivers/gpu/nvgpu/common/semaphore.c +++ b/drivers/gpu/nvgpu/common/semaphore.c @@ -106,7 +106,7 @@ void nvgpu_semaphore_sea_destroy(struct gk20a *g) */ struct nvgpu_semaphore_sea *nvgpu_semaphore_sea_create(struct gk20a *g) { - if (g->sema_sea) { + if (g->sema_sea != NULL) { return g->sema_sea; } @@ -119,11 +119,11 @@ struct nvgpu_semaphore_sea *nvgpu_semaphore_sea_create(struct gk20a *g) g->sema_sea->page_count = 0; g->sema_sea->gk20a = g; nvgpu_init_list_node(&g->sema_sea->pool_list); - if (nvgpu_mutex_init(&g->sema_sea->sea_lock)) { + if (nvgpu_mutex_init(&g->sema_sea->sea_lock) != 0) { goto cleanup_free; } - if (__nvgpu_semaphore_sea_grow(g->sema_sea)) { + if (__nvgpu_semaphore_sea_grow(g->sema_sea) != 0) { goto cleanup_destroy; } diff --git a/drivers/gpu/nvgpu/gv100/gr_gv100.c b/drivers/gpu/nvgpu/gv100/gr_gv100.c index 4bcbed857..3cf8e8d8d 100644 --- a/drivers/gpu/nvgpu/gv100/gr_gv100.c +++ b/drivers/gpu/nvgpu/gv100/gr_gv100.c @@ -132,7 +132,7 @@ static int gr_gv100_scg_estimate_perf(struct gk20a *g, num_tpc_mask &= ~(0x1 << disable_tpc_id); is_tpc_removed_pes = true; } - if (hweight32(num_tpc_mask)) { + if (hweight32(num_tpc_mask) != 0UL) { scg_num_pes++; } }