gpu: nvgpu: mm: fix CERT-C INT31 violations in vm.c

Rule INT31 requires integer conversions do not result in losing or
misinterpreting data. For most cases, use the safe cast operations.

For one case, the conditional operator was being used for s16 values
which were being promoted to ints. So, replace the conditional operator
with an if statement.

JIRA NVGPU-3517

Change-Id: Iac466911b0dd3893e7e7a188e372272b14591b60
Signed-off-by: Philip Elcan <pelcan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2127425
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Philip Elcan
2019-05-29 13:33:51 -04:00
committed by mobile promotions
parent 23eaac0f33
commit c2bf4a4e8f
2 changed files with 11 additions and 7 deletions

View File

@@ -276,7 +276,7 @@ static int nvgpu_init_sema_pool(struct vm_gk20a *vm)
nvgpu_safe_sub_u64(vm->va_limit,
mm->channel.kernel_size),
512U * PAGE_SIZE,
(u32)SZ_4K);
nvgpu_safe_cast_u64_to_u32(SZ_4K));
if (nvgpu_semaphore_sea_get_gpu_va(sema_sea) == 0ULL) {
nvgpu_free(&vm->kernel,
nvgpu_semaphore_sea_get_gpu_va(sema_sea));
@@ -336,9 +336,11 @@ int nvgpu_vm_do_init(struct mm_gk20a *mm,
vm->mm = mm;
vm->gmmu_page_sizes[GMMU_PAGE_SIZE_SMALL] = (u32)SZ_4K;
vm->gmmu_page_sizes[GMMU_PAGE_SIZE_SMALL] =
nvgpu_safe_cast_u64_to_u32(SZ_4K);
vm->gmmu_page_sizes[GMMU_PAGE_SIZE_BIG] = big_page_size;
vm->gmmu_page_sizes[GMMU_PAGE_SIZE_KERNEL] = (u32)SZ_4K;
vm->gmmu_page_sizes[GMMU_PAGE_SIZE_KERNEL] =
nvgpu_safe_cast_u64_to_u32(SZ_4K);
/* Set up vma pointers. */
vm->vma[GMMU_PAGE_SIZE_SMALL] = &vm->user;
@@ -921,9 +923,11 @@ int nvgpu_vm_map(struct vm_gk20a *vm,
binfo.flags = flags;
binfo.size = nvgpu_os_buf_get_size(os_buf);
binfo.compr_kind =
(vm->enable_ctag && compr_kind != NVGPU_KIND_INVALID ?
compr_kind : NVGPU_KIND_INVALID);
if (vm->enable_ctag && compr_kind != NVGPU_KIND_INVALID) {
binfo.compr_kind = compr_kind;
} else {
binfo.compr_kind = NVGPU_KIND_INVALID;
}
binfo.incompr_kind = incompr_kind;
if (compr_kind != NVGPU_KIND_INVALID) {

View File

@@ -219,7 +219,7 @@ struct vm_gk20a {
#define NVGPU_VM_MAP_L3_ALLOC BIT32(5)
#define NVGPU_VM_MAP_PLATFORM_ATOMIC BIT32(6)
#define NVGPU_KIND_INVALID -1
#define NVGPU_KIND_INVALID S16(-1)
void nvgpu_vm_get(struct vm_gk20a *vm);
void nvgpu_vm_put(struct vm_gk20a *vm);