From 8f15a2903c16521545c3c3039d0bea63f23bf079 Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Fri, 7 Dec 2018 10:15:26 -0500 Subject: [PATCH] gpu: nvgpu: unit: initialize nvgpu_mem variables There were several places were nvgpu_mem structs were declared on the stack and not initialized. Some fields could be used erroneously by underlying APIs. To allow the initialization of an array of nvgpu_mem in test_dma_alloc_fi_delayed_enable(), the array length had to be changed from a const to a macro. JIRA NVGPU-1563 Change-Id: I6c23445af7d932710898df2e23a8fd892bee77b3 Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/1967966 Reviewed-by: svc-mobile-coverity Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/units/mm/nvgpu_sgt/nvgpu_sgt.c | 4 ++-- userspace/units/mm/page_table/page_table.c | 8 ++++---- .../posix-fault-injection-dma-alloc.c | 16 ++++++++-------- userspace/units/pramin/nvgpu-pramin.c | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/userspace/units/mm/nvgpu_sgt/nvgpu_sgt.c b/userspace/units/mm/nvgpu_sgt/nvgpu_sgt.c index 748656842..94f51a970 100644 --- a/userspace/units/mm/nvgpu_sgt/nvgpu_sgt.c +++ b/userspace/units/mm/nvgpu_sgt/nvgpu_sgt.c @@ -72,7 +72,7 @@ static int test_nvgpu_sgt_basic_apis(struct unit_module *m, struct gk20a *g, { int ret = UNIT_SUCCESS; struct nvgpu_os_posix *p = nvgpu_os_posix_from_gk20a(g); - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; struct nvgpu_sgt *sgt; struct nvgpu_mem_sgl *sgl; struct nvgpu_sgt_ops const *saved_ops_ptr; @@ -404,7 +404,7 @@ static int test_nvgpu_sgt_alignment_with_iommu(struct unit_module *m, { int ret = UNIT_SUCCESS; struct nvgpu_os_posix *p = nvgpu_os_posix_from_gk20a(g); - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; struct nvgpu_sgt *sgt; struct nvgpu_mem_sgl *sgl; u64 alignment; diff --git a/userspace/units/mm/page_table/page_table.c b/userspace/units/mm/page_table/page_table.c index d84fe8830..ceaf804e4 100644 --- a/userspace/units/mm/page_table/page_table.c +++ b/userspace/units/mm/page_table/page_table.c @@ -344,7 +344,7 @@ static u64 pte_get_phys_addr(u32 *pte) static int test_nvgpu_gmmu_map_unmap(struct unit_module *m, struct gk20a *g, void *args) { - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; u32 pte[2]; int result; struct nvgpu_os_posix *p = nvgpu_os_posix_from_gk20a(g); @@ -443,7 +443,7 @@ static int test_nvgpu_gmmu_map_unmap(struct unit_module *m, static int test_nvgpu_gmmu_set_pte(struct unit_module *m, struct gk20a *g, void *args) { - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; u32 pte[2]; int result; struct nvgpu_os_posix *p = nvgpu_os_posix_from_gk20a(g); @@ -582,7 +582,7 @@ static void gmmu_unmap_advanced(struct vm_gk20a *vm, struct nvgpu_mem *mem, static int test_nvgpu_gmmu_map_unmap_adv(struct unit_module *m, struct gk20a *g, void *args) { - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; u64 vaddr; struct test_parameters *params = (struct test_parameters *) args; @@ -609,7 +609,7 @@ static int test_nvgpu_gmmu_map_unmap_adv(struct unit_module *m, static int test_nvgpu_gmmu_map_unmap_batched(struct unit_module *m, struct gk20a *g, void *args) { - struct nvgpu_mem mem, mem2; + struct nvgpu_mem mem = { }, mem2 = { }; u64 vaddr, vaddr2; struct vm_gk20a_mapping_batch batch; diff --git a/userspace/units/posix/fault-injection/posix-fault-injection-dma-alloc.c b/userspace/units/posix/fault-injection/posix-fault-injection-dma-alloc.c index f7c0e066e..52ae42bea 100644 --- a/userspace/units/posix/fault-injection/posix-fault-injection-dma-alloc.c +++ b/userspace/units/posix/fault-injection/posix-fault-injection-dma-alloc.c @@ -74,7 +74,7 @@ int test_dma_alloc_init(struct unit_module *m, int test_dma_alloc_fi_default(struct unit_module *m, struct gk20a *g, void *__args) { - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; int result; int ret = UNIT_SUCCESS; @@ -118,7 +118,7 @@ test_exit: int test_dma_alloc_fi_enabled(struct unit_module *m, struct gk20a *g, void *__args) { - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; int result; int ret = UNIT_SUCCESS; @@ -164,9 +164,9 @@ test_exit: int test_dma_alloc_fi_delayed_enable(struct unit_module *m, struct gk20a *g, void *__args) { - const unsigned int fail_after = 2; +#define FAIL_AFTER 2 unsigned int call_count = 0; - struct nvgpu_mem mem[fail_after+1]; + struct nvgpu_mem mem[FAIL_AFTER+1] = { }; int result = 0; int ret = UNIT_SUCCESS; @@ -177,7 +177,7 @@ int test_dma_alloc_fi_delayed_enable(struct unit_module *m, } /* enable fault injection after delay */ - nvgpu_posix_enable_fault_injection(dma_fi, true, fail_after); + nvgpu_posix_enable_fault_injection(dma_fi, true, FAIL_AFTER); if (nvgpu_posix_is_fault_injection_triggered(dma_fi)) { unit_err(m, "Fault injection errantly enabled too soon\n"); ret = UNIT_FAIL; @@ -185,17 +185,17 @@ int test_dma_alloc_fi_delayed_enable(struct unit_module *m, } call_count = 1; - while (call_count <= (fail_after+1)){ + while (call_count <= (FAIL_AFTER+1)) { result = nvgpu_dma_alloc(g, TEST_DEFAULT_SIZE, &mem[call_count-1]); - if ((call_count <= fail_after) && (result != 0U)) { + if ((call_count <= FAIL_AFTER) && (result != 0U)) { unit_err(m, "nvgpu_dma_alloc returned error when fault " "injection disabled\n"); ret = UNIT_FAIL; /* no reason to go on */ break; - } else if ((call_count > fail_after) && (result == 0U)) { + } else if ((call_count > FAIL_AFTER) && (result == 0U)) { unit_err(m, "nvgpu_dma_alloc returned success when " "fault injection enabled\n"); ret = UNIT_FAIL; diff --git a/userspace/units/pramin/nvgpu-pramin.c b/userspace/units/pramin/nvgpu-pramin.c index 558020734..6bb5af58f 100644 --- a/userspace/units/pramin/nvgpu-pramin.c +++ b/userspace/units/pramin/nvgpu-pramin.c @@ -272,7 +272,7 @@ static int test_pramin_rd_n_single(struct unit_module *m, struct gk20a *g, void *__args) { u32 *dest; - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; struct nvgpu_mem_sgl *sgl; u32 byte_cnt = TEST_SIZE; bool success = false; @@ -336,7 +336,7 @@ static int test_pramin_wr_n_multi(struct unit_module *m, struct gk20a *g, void *__args) { u32 *src; - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; struct nvgpu_mem_sgl *sgl1, *sgl2, *sgl3; u32 byte_cnt = TEST_SIZE; u32 byte_offset = SZ_128K; @@ -425,7 +425,7 @@ free_src: static int test_pramin_memset(struct unit_module *m, struct gk20a *g, void *__args) { - struct nvgpu_mem mem; + struct nvgpu_mem mem = { }; struct nvgpu_mem_sgl *sgl; u32 byte_cnt = TEST_SIZE; u32 word_cnt = byte_cnt / sizeof(u32);